Javascript判断哪一个radio被选中,可以用jquery的选择器方便的找到和判断。
选择器的写法像这样$("[name=radio的name]:checked")。
这是针对此问题的测试页面。
1、这是html代码,有2个ratio,name都是"sex",值分别为"男"和"女"
男:
<input type="radio" name="sex" value="男" />
<br />
女:
<input type="radio" name="sex" value="女" />
<br/>
<br/>
<button id="button">
选中的性别是
</button>
2、在javascript代码中,绑定按钮事件,点击时用选择器判断哪个ratio选中并d窗。
$(function() {
$("#button").click(function() {
var val = $("[name=sex]:checked").val()
val = val || '未选中'
alert(val)
})
})
这是运行效果
rate 和ratio的区别是:
rate (名词)速度,速率,比率, 频率,等级, 价格,费用,税率,(利息等的)费率,利率,(复数形式,指英国)地方税,不动产税,房地产税 。例如:
The rate at which hair grows can be agonisingly slow. 头发生长的速度可能极其缓慢。
His heart rate was 30 beats per minute slower. 他的心率每分钟慢了30次。
The rate of inflation is running at about 2.7 percent. 通货膨胀率大约为2.7%。
Calls cost 36p per minute cheap rate and 48p at all other times. 优惠时段的话费是每分钟36便士,其他时段是48便士。
East German wages were converted at the rate of one old East mark for one Deutschmark. 东德的工资兑换比率是一个旧东德马克兑换一个德国马克。
The government insisted that it would not be panicked into interest rate cuts. 政府坚称不会陷入恐慌而匆忙降息。
Soldiers were exempt from paying rates. 士兵免缴地方税。
2. ratio (名词)比,比率,比例,系数。例如:
In 1978 there were 884 students at a lecturer/student ratio of 1:15. 1978年有884名学生,师生比为1比15。
The bottom chart shows the ratio of personal debt to personal income. 下面的图表显示了个人负债与个人收入之比。
The adult to child ratio is 1 to 6. 成人与儿童的比例为1比6。
What is the ratio of men to women in the department?这个部门的男女比例是多少?
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)