我有点困惑.
我有一个用户可以单击的复选框,用于确定我的页面上的私人电话号码是对所有人还是仅对管理员可见.当单击该框时,我想确保您首先被允许首先打印它的状态仅用于测试目的.当我运行此功能时,它会运行两次.
我在其他地方读到这是因为Callbacks?但我回复假,所以这不应该是这样的吗?
我不是一个@L_301_0@向导,所以我仍然不了解JavaScript及其与ASP的交互.
- /**
- * Used to Check whether a Private Phone number should be hidden or shown.
- */
- function ValidateHidePrivate() {
- if (scope["pickeduser"] != scope["credential"]) {
- alert("Not allowed");
- return false;
- } else {
- alert(document.getElementById("HidePrivate").checked);
- return false;
- }
- }
和HTML:
- <label for="HidePrivate" onclick="ValidateHidePrivate()">
- <input type="checkBox" name="HidePrivate" id="HidePrivate" value="no" />
- Hide my Private Phone Number
- </label>
有帮助吗?
解决方法
这是因为< label>使用for属性会引发< input type =“checkBox”>的点击事件.单击时关联的元素.
您应该将click事件处理程序绑定到输入,而不是标签.
- function ValidateHidePrivate() {
- alert();
- }
- <label for="HidePrivate" >
- <input type="checkBox" name="HidePrivate" onclick="ValidateHidePrivate()" id="HidePrivate" value="no" />
- Hide my Private Phone Number
- </label>