When the input radio value is Chinese, js gets the radio

When doing user information management, there is a gender attribute. I use mysql enum, so sex is a string, and the value of input is directly set to "female", "male", and then I want to get radio in js, and check it online. There are some methods, other people's sex attribute value is 0 or 1, the acquisition method is:

$("input:radio[name='userDetail.sex']).eq(0).attr("checked",true);

But when I use this method to get the value attribute of the radio to be Chinese, I can't get the value:

$("input:radio[name='userDetail.sex']).eq('女').attr("checked",true);

Finally found a way:

            if(sex=="女"){
                $("input:radio[name='userDetail.sex'][value=女]").attr("checked",true);
            }
            else if(sex=="男"){
                $("input:radio[name='userDetail.sex'][value=男]").attr("checked",true);
            }else{
                $("input:radio[name='userDetail.sex']").attr("checked",false);
            }

Record it so you don't forget it later.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325636397&siteId=291194637