input radio单选框绑定change事件

 

html页面:html

<input type="radio" name="sex" value="female">female <input type="radio" name="sex" value="male">male

 

js部分代码:this

$(document).ready(function() { $('input[type=radio][name=sex]').change(function() { if (this.value == 'female') { console.log("female"); } else if (this.value == 'male') { console.log("male"); } }); });
相关文章
相关标签/搜索