关于jquery有关问题
关于jquery问题
$(document).ready(function(){
$("#cr").click(function(){
if(this.checked){ //DOM方式判断
alert("感谢你的支持!你可以继续操作!");
}
})
});
为什么这样写不对呢
$(this)
if($(this).checked){ //DOM方式判断
alert("感谢你的支持!你可以继续操作!");
}
为什么这样写不对呢
------解决方案--------------------
checked是javascript的属性,jquery没有这个属性
------解决方案--------------------
this 指向你操作的dom对象
$(this) 则返回一个jQuery 对象,后者对dom对象进行了包装,所有的操作都要另外按jQuery的方法进行.
------解决方案--------------------
$(document).ready(function(){
$("#cr").click(function(){
if(this.checked){ //DOM方式判断
alert("感谢你的支持!你可以继续操作!");
}
})
});
为什么这样写不对呢
$(this)
if($(this).checked){ //DOM方式判断
alert("感谢你的支持!你可以继续操作!");
}
为什么这样写不对呢
------解决方案--------------------
checked是javascript的属性,jquery没有这个属性
------解决方案--------------------
this 指向你操作的dom对象
$(this) 则返回一个jQuery 对象,后者对dom对象进行了包装,所有的操作都要另外按jQuery的方法进行.
------解决方案--------------------
$(document).ready(function () {
$("#cr").click(function () {
if (this.checked) { //DOM方式判断
alert("感谢你的支持!你可以继续操作!");
}
})
});
$(document).ready(function () {
$("#cr").click(function () {
if ($(this).attr("checked")) { //Jquery方式判断
alert("感谢你的支持!你可以继续操作!");
}
})
});
$(document).ready(function () {
$("#cr").click(function () {
if ($(this)get(0).checked)){ //DOM方式判断 $(this)[0],$(this).get(0) Jquery对象转成DOM
alert("感谢你的支持!你可以继续操作!");
}
})
});