我在一个正在研究的项目中找到了这个:
<% If Session("VALUE1") <> "" Then %>
document.forms[0].action= "<%=Session("VALUE1")%>";
<% Else %>
document.forms[0].action="NewPage.aspx"
<% End If %>
Run Code Online (Sandbox Code Playgroud)
当我从顶行单步执行此操作时,代码会跳过If会话("VALUE1"),但也跳过Else.这怎么可能?
运行以下代码并按下按钮应该会记录到控制台窗口 2 个元素,即带有class="test1"、按钮和 的p元素。并且console.log(el.length)是2。但控制台记录的内容是这样的:
[p#div1.test1,
button#btn.test1,
div1: p#div1.test1,
btn: button#btn.test1]
Run Code Online (Sandbox Code Playgroud)
看起来4元素不是2。
这里发生了什么?
<html>
<body>
<p class="test1" id="div1">test1</p>
<button id="btn" onclick="getElements()" class="test1">Get Element List</button>
<script>
function getElements()
{
var txt = document.getElementById("div1").innerHTML;
var el = document.getElementsByClassName(txt);
if (el) {
console.log(el);
console.log(el.length);
}
}
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)