function changeValue(this) {
if (this.checked) {
$(this).value=1;
} else {
$(this).value=0;
}
}
上面的代码没有反应
function changeValue() {
if (document.getElementById('auto-backup').checked) {
document.getElementById('auto-backup').value=1;
} else {
document.getElementById('auto-backup').value=0;
}
}
这段代码得到想要的效果了
我的问题是如何把第一段代码实现,用this实现
我直接绑定click函数,下面这段代码搞对了
$("#auto-backup").click(function(){
if (this.checked) {
this.value=1;
} else {
this.value=0;
}
});
下面这段代码搞对了
function changeValue(that) {
if (that.checked) {
that.value=1;
} else {
that.value=0;
}
}
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
this 是关键字,不能作为函数的参数。改成下面这样就好了。
不能這樣使用
this,this為關鍵字不能當作參數名你用的this是jquery 没库跑不了,你自己看看。