Javascript 根据单选按钮填充输入
我有这些单选按钮:Javascript 根据单选按钮填充输入,javascript,jquery,html,Javascript,Jquery,Html,我有这些单选按钮: <table border="0" cellspacing="0" cellpadding="0"> <tr> <td><input id="rooom" name="room" type="radio" value="single"><strong>Single Room: 85 euros</strong></td> <td width="30">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input id="rooom" name="room" type="radio" value="single"><strong>Single Room: 85 euros</strong></td>
<td width="30"></td>
<td><input id="rooom" name="room" type="radio" value="double"><strong>Double Room: 95 euros</strong></td>
</tr>
</table>
这是语法:
$(".rooom").change(function () {
var sel = $(this).val();
if (sel == 'single') {
$("#cost").val('85');
}
if (sel == 'double') {
$("#cost").val('95');
}
});
记住总是用}关闭jQuery函数
rooom也是一个类,而不是一个id,因此您需要将其替换为一个。JS上的分号是可选的。哦,删除了。谢谢你的提醒!
$("#rooom").change(function() {
var sel = $(this).val();
if (sel=='single') {
$("#cost").val('85')
}
if (sel=='double') {
$("#cost").val('95')
}
$(".rooom").change(function () {
var sel = $(this).val();
if (sel == 'single') {
$("#cost").val('85');
}
if (sel == 'double') {
$("#cost").val('95');
}
});