admin管理员组文章数量:1277502
I have these two radio buttons:
Original <input id="video_is_derivative_false" name="video[is_derivative]" type="radio" value="false">
Derivative (<i>ex. remix, mashup etc...</i>) <input id="video_is_derivative_true" name="video[is_derivative]" type="radio" value="true">
and I want to call some jQuery code when the "Derivative" button is selected. How can I do this?
I have these two radio buttons:
Original <input id="video_is_derivative_false" name="video[is_derivative]" type="radio" value="false">
Derivative (<i>ex. remix, mashup etc...</i>) <input id="video_is_derivative_true" name="video[is_derivative]" type="radio" value="true">
and I want to call some jQuery code when the "Derivative" button is selected. How can I do this?
Share Improve this question edited Dec 7, 2022 at 16:54 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jun 17, 2011 at 21:44 Justin MeltzerJustin Meltzer 13.6k34 gold badges119 silver badges182 bronze badges5 Answers
Reset to default 3Just attach a change event to it:
$('#video_is_derivative_true').change(function(){
console.log("Selected");
})
example: http://jsfiddle/niklasvh/cyADB/
$("#video_is_derivative_true").click(function(){
alert("your code goes here");
});
Add an onclick handler to the input tag
You could also put something on the change handler
$("#video_is_derivative_true").change(function(){
if($(this).is(':checked')){
alert("more code here");
}
});
You will want to monitor the change event, then in the handler, check to make sure that the button is checked. The second part is important because the change event will also fire when it bees unchecked. The code would look something like this:
$('#video_is_derivative_true').change(function() {
if (this.checked) {
alert('derivative checked!');
}
});
Here's a live demo ->
$('#video_is_derivative_true').bind('click change', function() {
if (this.checked) {
// derivative is checked
}
});
$("#video_is_derivative_true").click(function(){ alert("your code goes here"); });
本文标签: javascriptTrigger some jQuery code when a radio button is selectedStack Overflow
版权声明:本文标题:javascript - Trigger some jQuery code when a radio button is selected - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741269538a2369016.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论