我有兩個單選按鈕,並且我希望在檢查其中一個時顯示警報,但似乎問題在於它無法識別該元素警報不會彈出!無法與JQuery一起使用RadioButton - 警報不會彈出
用於工作時,此代碼,但它不會了(我想我改變的要素之一的標識,這就是導致問題)
JS:
/*This function is responsible for for the radio buttons*/
$(function() {
$(".r1").checkboxradio({
icon: false
});
});
/*This function changes the RecordTypeId according to the BankEmployeeCheckbox*/
$("form input:radio").change(function() {
if ($(this).val() == "Yes") {
document.getElementById("recordType").value = "01220000000FdvyAAC";
alert("Yes");
} else {
document.getElementById("recordType").value = "01220000000FffjAAC";
console.log(document.getElementById("recordType").value);
alert("No");
}
});
HTML
<form method='post' id='prechatForm' autocomplete="on">
<div id="bankEmployeeYesNoRadioButtonDiv">
<label>{!$Label.Bank_Employee}</label><br/>
<label for="radio-1" class="radioLabel">{!$Label.Yes}</label>
<input type="radio" name="liveagent.prechat:BankEmployee" id="radio-1" class="r1" value="Yes"></input>
<label for="radio-2" class="radioLabel">{!$Label.No}</label>
<input type="radio" name="liveagent.prechat:BankEmployee" id="radio-2" class="r1" value="No"></input>
</div>
</form>
結果:當我點擊一個單選按鈕,沒有任何反應,沒有警報。 無控制檯錯誤 注意:請注意,我正在使用Salesforce(Visualforce)語法。
你會得到什麼錯誤?另外,輸入是自閉的。沒有''。最後,你的例子沒有'
嘗試改變這個$(「form input:radio」)。change(function()to this $ 「form input [type ='radio']」)。change(function() –
@ j08691,1)沒有提示2)這是Salesforce(visualforce)的語法,這就是爲什麼我必須使用閉合元素。這只是一個片段而不是完整的代碼4)我會嘗試你最後的建議 – Dante