繁体   English   中英

奇怪的是,第二次单击切换隐藏/显示按钮后,未先单击即可工作

[英]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>")

尝试显式设置显示,这是样式的显示,而不是是否显示。 所以在行之后:

retstr.AppendLine(“ class ='item'”)

添加以下行

retstr.AppendLine(“ style ='display:block'”)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM