复选框不会取消选中 jQuery 的更改事件
checkbox is not unchecking on the change event of the jquery
我有一个复选框和我的 asp.net 网站中的按钮,按钮CSS属性在页面加载时设置为隐藏,借助复选框我想显示和隐藏 asp.net 按钮,问题是复选框被选中但我无法取消选中它....请帮忙,我给了代码
<script>
$(function () {
$("#Btnforgotpass").css('display', 'none');
});
$(document).ready(function () {
$("[id$=chkforgotpass]").change(function () {
if (document.getElementById("chkforgotpass").checked = true) {
alert('checked');
$("[id$=Btnforgotpass]").css('display', 'inline');
}
else {
alert('unchecked');
$("[id$=Btnforgotpass]").css('display', 'none');
}
});
});
</script>
在您的 if 语句上尝试将 = 更改为 === 您正在分配而不是使用此语句进行比较
$(function() {
$("#Btnforgotpass").css('display', 'none');
});
$(document).ready(function() {
$("[id$=chkforgotpass]").change(function() {
if (document.getElementById("chkforgotpass").checked === true) {
alert('checked');
$("[id$=Btnforgotpass]").css('display', 'inline');
} else {
alert('unchecked');
$("[id$=Btnforgotpass]").css('display', 'none');
}
});
});
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<button id="Btnforgotpass">
Button
</button>
<input type="checkbox" id="chkforgotpass">
</body>
</html>
将
if (document.getElementById("chkforgotpass").checked = true) {
更改为if (document.getElementById("chkforgotpass").checked == true) {
如果你使用的是jQuery,这样做太简单了。
$(document).ready(function() {
$("[id$=chkforgotpass]").change(function() {
var isChecked = $(this).is(":checked") : "inline" : "none";
$("[id$=Btnforgotpass]").css('display', isChecked);
});
});
相关文章:
- 选择onclick事件jquery
- 用于多个类事件Jquery的单个函数
- 激发滑块's幻灯片事件jquery ui
- 设置重复按钮以注册点击事件jquery
- 保留当前点击事件jquery
- 启动/停止按键事件jquery
- 在事件jquery中插入一个函数
- 删除克隆的事件JQuery
- typeahead选择事件(jQuery)的动态绑定
- 触发自定义事件 Jquery
- 绑定两次或更多次的事件 jquery
- 单击时的事件 jquery 不起作用
- 在鼠标悬停事件 jquery 上显示边框的内容
- 同时触发两个鼠标事件 jQuery
- 焦点事件 jquery 组合框/自动完成
- 如何在页面中捕获“正文”和“正文”事件[Jquery].
- 将对象传递给事件 jQuery
- 验证“取消”上的字段 单击Onbeforeunload事件JQUERY
- 复选框单击事件 jQuery 不起作用
- 口述事件jquery顺序