input radio单选框绑定change事件

 

html页面:

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

 

js部分代码:

$(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");
        }
    });
});

 

posted @ 2019-03-12 11:02  Fourteen  阅读(7977)  评论(0编辑  收藏  举报