2014-09-24 43 views
0

我有這些單選按鈕:取決於單選按鈕,填寫輸入

<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> 

我想值出現在此輸入:

(...) 
<td><label>Cost of Accomodation =</label></td> 
<td width="5"></td> 
<td><input id="cost" class="input_reg_cost" name="cost" type="text"></td> 
(...) 

這是我的劇本,但它不是工作,我不知道它是否是他的語法或錯誤我的。

$("#rooom").change(function() { 
    var sel = $(this).val(); 
    if (sel=='single') { 
    $("#cost").val('85') 
    } 
    if (sel=='double') { 
    $("#cost").val('95')   
    } 

回答

2

這句法:

$(".rooom").change(function() { 
    var sel = $(this).val(); 
    if (sel == 'single') { 
     $("#cost").val('85'); 
    } 
    if (sel == 'double') { 
     $("#cost").val('95'); 
    } 
}); 

記得用,始終密切jQuery函數});

rooom也是一個類,而不是一個ID,所以你會想用#替換#。

+1

JS上的分號是可選的。 – LcSalazar 2014-09-24 22:26:26

+1

哎呀,刪除。感謝您的提醒! – Firedrake969 2014-09-24 22:28:06

相關問題