奇怪的是,在第二次单击切换隐藏/显示按钮而不是第一次单击后,有两行有效
Strangely, two lines work after SECOND click of toggle hide/show button not FIRST click
第二次
单击切换按钮后,一切都可以完美运行。有些行在第一次单击时正常工作,因此我知道正在输入 if 和 else 内容。请参阅代码注释以更好地理解。我的逻辑哪里有问题,导致这两行在第一次点击后不起作用?即使您不确切知道问题所在,也希望了解可能导致此问题的任何想法。
function toggleView(switchImgTag) {
var cnt = 0;
var but = document.getElementById("but_Toggle");
while (cnt <= 5000) {
window['ele' + cnt] = document.getElementById('camimg' + cnt);
window['imageEle' + cnt] = document.getElementById('camimg' + cnt);
if (window['ele' + cnt].style.display == "block") {
but.innerHTML = "Thumbs"; //Strangely, executes after "second" click of List button
window['ele' + cnt].style.display = "none"; //Strangely, executes after "second" click of List button
document.getElementById('im' + cnt).style.width = '20px'; //Executes after very first click of List button as it should
document.getElementById('im' + cnt).style.visibility = 'visible'; //Executes after very first click of List button as it should
}
else {
but.innerHTML = "List";
window['ele' + cnt].style.display = "block";
document.getElementById('im' + cnt).style.width = '1px'; //Executes after first click of List button as it should
document.getElementById('im' + cnt).style.visibility = 'hidden'; //Executes after very first click of List button as it should
}
cnt++;
}
}
然后我有按钮..
<button id="but_Toggle" type="button" onclick="javascript:toggleView();">List</button>
然后我控制了内容...
retstr.AppendLine("<img alt ='" & streamref & "'")
retstr.AppendLine(" title ='" & Trim(image_title_with_PTZ) & " - " & streamref & "'")
retstr.AppendLine(" src = '" & imgsrc & "'")
retstr.AppendLine(" class = 'item'")
If searchbar = False Then
retstr.AppendLine(" id = 'camimg" & count & "'")
Else
retstr.AppendLine(" id = 'camimg" & count & "'")
End If
retstr.AppendLine(" ondblclick = ""javascript:window.open('" & imgsrc & "')""")
'retstr.AppendLine(" data-streamurl='" & "rtsp://127.0.0.1/cam.stream" & "'")
retstr.Append("/></div>")
retstr.AppendLine("<div class='preview'")
retstr.AppendLine(" title ='" & Trim(image_title_with_PTZ) & " - " & streamref & "'")
retstr.AppendLine(" id = '" & imgsrc & "'")
retstr.AppendLine(">")
retstr.Append("<div class=imagename><img alt ='" & streamref & "' title ='" & Trim(image_title_with_PTZ) & " - " & streamref & "'" & " id='im" & count & "' src='../images/cam.png' height=20 class=item2 ondblclick =javascript:window.open('" & imgsrc & "')><font size=1><a href='" & imgsrc & "'>" & image_title_with_PTZ & "</a></font></nb></span></div></div>")
尝试显式设置显示,这是样式的显示,而不是是否显示。所以在行之后:
雷斯特。AppendLine(" class = 'item'")
添加以下行
雷斯特。AppendLine(" style = 'display:block'")
相关文章:
- 当单击第一个李时,它显示内容一,当单击第二个李时,它显示内容二
- 单击一次后禁用按钮-第2部分
- 如何对每个用户每天只允许单击一次的按钮进行编码
- button.单击两次删除附加操作后不工作
- 为什么jQuery下拉列表需要单击两次
- 单击3次后禁用按钮
- 为什么在文本框内按回车键,单击第一个按钮并提交表单
- 为每个字母单击一次
- Rails-jQuery 为什么我必须单击两次才能显示 jQuery 效果
- 对同一类中的所有元素单击一次
- 单击一次以静音,另一次单击可取消静音
- 必须单击两次才能得到一个响应
- 如何在幻灯片中添加向上滚动功能单击1次即可向下滚动
- 如何加载一个html页面并在其中只需单击一次即可运行函数
- Javascript:表单在第一次验证和应用样式后提交
- 页面加载后的第一个锚定链接需要单击两次
- 在同一元素上单击两次,然后在另一个元素上单击两次,使第一个元素进入“单击”状态
- JavaScript单击事件只在InfoPath表单上第一次触发
- Ajax + JSF在第一次单击后单击2次
- 表单在第一次单击后N秒自动提交