【发布时间】:2017-06-06 00:24:52
【问题描述】:
我有两个单选按钮,我想在其中一个被选中时显示一个警报,似乎问题是它无法识别元素,因为警报没有弹出!
这段代码过去可以工作,但现在不行了(我想我更改了其中一个元素的 ID,这就是导致问题的原因)
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) 语法。
【问题讨论】:
-
您遇到什么错误?此外,输入是自动关闭的。没有
</input>。最后,您的示例没有<form>元素或 ID 为recordType的元素。如果你使用 jQuery,那么 use jQuery。这个$("#recordType").val()不是document.getElementById("recordType").value -
尝试把这个 $("form input:radio").change(function() 改成这个 $("form input[type = 'radio']").change(function()跨度>
-
@j08691 ,1) 没有显示警报 2) 这是 Salesforce (visualforce) 语法,这就是我必须使用关闭元素的原因。3) 抱歉,这只是一个 sn-p,而不是完整代码4) 我会试试你最后的建议
标签: jquery html radio-button