0
我是一個新開發者,我創建了變化事件函數兩個單選按鈕同名& id和不同的值,我會調用change事件觸發器,但是默認值的相關內容在單選按鈕變化前沒有顯示。請幫助我如何解決這個問題。如何顯示默認值jQuery單選按鈕更改事件?
**html code**
<td valign="top" width="37.5%">
<label><input type="radio" name="client_location_c" value="germany" checked="checked" id="client_location_c" accesskey="7" title="">Global Guide Services GmbH (Germany)</label><br>
<label><input type="radio" name="client_location_c" value="romania" id="client_location_c" accesskey="7" title="">Global Guide Services SRL (Romania)</label><br>
</td>
jQuery的
$("input[name='client_location_c']").change(function() {
var receipientData = "";
if ($(this).val() == 'germany') {
receipientData = locationBasedGermanyRecipient;
} else if ($(this).val() == 'romania') {
receipientData = locationBasedRomaniaRecipient;
}
autopopulateData(receipientData);
});
$("input[name='client_location_c']").trigger('change');
你能解釋一下'默認值相關內容未顯示單選按鈕更改前 – madalinivascu
不要對兩個或多個元素使用相同的ID,您可以對這些元素使用相同的類名稱。 –