jQuery 从input中读取的内容的类型

如下HTML代码:


Yes
No


使用jQuery代码去读取radio的值:

var value1 = $('input[name=test1]').val();

//check the value1

if(value1 == true)

//do something

else

//do otherthing

问题来了:如果该radio控件是选择Yes还是No,if条件判断分支总是满足//do otherthing

原因:value1是字符串类型,即其值为"true"/"false"。

所有需要将jQuery代码修改如下:

var value1 = $('input[name=test1]').val();

//check the value1

if(value1 == "true")

//do something

else

//do otherthing



你可能感兴趣的:(JQuery,HTML)