复选框jquery或JavaScript oncheck? [英] checkbox jquery or javascript oncheck?
问题描述
我不知道这个术语是否正确,但我想要的效果与onclick相同,但是对于带有jquery或javascript的复选框。
onclick版本:
< a href =...onclick =function()>连结< / a>
我想要与上面相同的效果,但对于复选框。最终的结果将是页面应该用更新的php查询重新加载,但是我可以做的那部分。
$ b 复选框:
< input type =checkboxname =changevalue =one/>更改php查询
您应该听取更改
事件,因为可以选择复选框或者也可以使用键盘取消选择。
:
$('input [type =checkbox] [name =change]')。change(function ){
if(this.checked){
//检查时做些什么
}
});
与普通JavaScript相似:
<$ p $ ($ this.checked){
// checkbox是对元素的引用在检查
}
}时做一些事情;
最后,尽管您不应该使用内联事件处理程序,但是如果您必须:
< input ... onchange =handler.call(this)/>
其中处理程序
就像上面显示的处理程序。
进一步阅读:
I do not know the correct terminology for this, but I want the same effect as onclick but for a check box with jquery or javascript.
onclick version:
<a href="..." onclick="function()">Link</a>
I want the same effect as above but for a checkbox. The end result will be that the page should reload with an updated php query, but that part I can do. I just don't know what the onclick is for checkboxes.
checkbox:
<input type="checkbox" name="change" value="one" />changes php query
You should listen to the change
event, as the checkbox can be selected or deselect with the keyboard too:
$('input[type="checkbox"][name="change"]').change(function() {
if(this.checked) {
// do something when checked
}
});
Similarly with plain JavaScript:
// checkbox is a reference to the element
checkbox.onchange = function() {
if(this.checked) {
// do something when checked
}
};
And last, although you really should not use inline event handlers, but if you have to:
<input ... onchange="handler.call(this)" />
where handler
is like the handlers shown above.
Further reading:
这篇关于复选框jquery或JavaScript oncheck?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!