运行复选框之后的一个函数,并使用jquery推送提交按钮 [英] run a function after checkbox checked and pushed submit button with jquery
本文介绍了运行复选框之后的一个函数,并使用jquery推送提交按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我有:
$ 我尝试运行一个函数后复选框选中并按下提交按钮b $ b
< form name =select>
< label for =Genre>< input type =checkboxchecked =checkedid =Genre> Genre< / label&
< input type =buttononclick =myFunction()value =submit>
< / form>
这是我的功能:
function myFunction(){
$(input [id = Genre] [checked] alert(genre is checked);
}
);
}
任何想法我做错了什么?
解决方案
如果您按ID选择,您只需使用:
$('#Genre')
如果您要选择所有复选框,
$('input [type =checkbox]')
pre>
如果您想选择一个选中的复选框,您可以使用:
pre>$('input [type =checkbox]:checked')
做某事当有人检查你需要添加一个事件监听器的复选框:
$('#Genre')。bind点击',function(){
//在ID类型的复选框被点击时做某事
if($(this).is(':checked')){
// check something when the checkbox is checked
}
})
i'm trying to run a function after checkbox checked and pushed submit button with jquery
this is what i have:
<form name="select">
<label for="Genre"><input type="checkbox" checked="checked" id="Genre">Genre</label>
<input type="button" onclick="myFunction()" value="submit">
</form>
this is my function:
function myFunction() {
$("input [id=Genre] [checked]").each(
function() {
alert("genre is checked");
}
);
}
any ideas what i'm doing wrong?
解决方案
If you select by ID you can just use:
$('#Genre')
If you want to select all checkboxes then you can just:
$('input[type="checkbox"]')
If you want to select a checked checkbox you can use:
$('input[type="checkbox"]:checked')
If you want to do something WHEN someone checks a checkbox you need to add an event listener:
$('#Genre').bind('click', function() {
// do something when checkbox with ID Genre is clicked
if ($(this).is(':checked')) {
// do something when the checkbox is checked
}
})
这篇关于运行复选框之后的一个函数,并使用jquery推送提交按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文