我有一个 JSP 页面,上面有一些 input submit
纽扣。现在基于我从 AJAX
得到的一些值请求我想控制 display and hiding of these input buttons
.所以我创建了spans
对于每个输入。并根据我从 AJAX 请求收到的变量值,我在那里操纵显示属性。但我没有得到正确的结果。
这是我的代码:
<td style="width: 600px"><span id="startspan"><input name="start" value="startActivity" type="submit" id="startbuttonid"></span></td>
<td style="width: 600px"><span id="holdspan"><input name="start" value="holdActivity" type="submit" id="holdbuttonid"></span></td>
<td style="width: 600px"><span id="cancelspan"><input name="start" value="cancelActivity" type="submit" id="cancelbuttonid"></span></td>
<td style="width: 600px"><span id="closespan"><input name="start" value="closeActivity" type="submit" id="closebuttonid"></span></td>
还有我的java script
我正在编写用于显示或隐藏它们的代码是::
if(temp1[15]=="InProcess"){
document.getElementById('startspan').style.display='none';
document.getElementById('holdspan').style.display = 'block';
document.getElementById('cancelspan').style.display = 'block';
document.getElementById('closespan').style.display = 'block';
}
if(temp1[15]=="New"){
document.getElementById('startspan').style.display='block';
document.getElementById('holdspan').style.display = 'none';
document.getElementById('cancelspan').style.display = 'block';
document.getElementById('closespan').style.display = 'none';
}
此处基于变量 temp1[15]
我收到的值(value)很好。我想显示或隐藏那些输入提交按钮。我正在以正确的方式进行操作,例如定义跨度或需要一些更正。基本上所有这些输入按钮都在 dialog box <div>
中。只有当一个函数被触发时才会打开,我在里面写了我的隐藏或显示跨度代码(上面写的)。需要帮忙。谢谢。
最佳答案
CSS 中的 display
属性还决定了它是像 block (DIV、P 等)还是内联元素(span、b 等),以及它的可见性。
对于您的跨度,您想改为这样做:
document.getElementById('span').style.display = 'inline';
如果它是一个 DIV,你将使用 block
,如果它是一个 IMG,你将使用 inline-block
。
关于javascript - 在 HTML 中隐藏和显示跨度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10353013/