带有单选按钮列表的Jquery ajax问题
HTML 将“名称”更改为“类” 或 您正在使用“#rbTemplateList”,它将引用rbTemplateList的id,但这是每个元素的名称。为简单起见,您可以将它们分配给同一个类: class='某物'带有单选按钮列表的Jquery ajax问题,jquery,attributes,Jquery,Attributes,HTML 将“名称”更改为“类” 或 您正在使用“#rbTemplateList”,它将引用rbTemplateList的id,但这是每个元素的名称。为简单起见,您可以将它们分配给同一个类: class='某物' 然后使用$(“.something”)。单击这是您的实际html还是输入不正确 ... $("input[name='rbTemplateList']").click(function() { ... 问题是您正在使用$(“#rbTemplateList”)将事件附加到单选按钮,但
然后使用$(“.something”)。单击这是您的实际html还是输入不正确
...
$("input[name='rbTemplateList']").click(function() {
...
问题是您正在使用$(“#rbTemplateList”)
将事件附加到单选按钮,但开始处的#表示元素的ID,而rbTemplateList在html中作为名称提供
您应该将选择器更改为$(“:input[name='rbTemplateList'])
$(document).ready(function() {
var f = document.frm;
$("#rbTemplateList").click(function() {
pkTemplate= getSelectedRadioValue(f.rbTemplateList);
$.ajax({
url: "ajaxColor.php",
type: "POST",
data: 'pkTemplate='+pkTemplate,
timeout: 5000,
beforeSend: function(){ },
error: function(XMLHttpRequest, textStatus, errorThrown) {
},
success: function(output) {
},
complete: function(){ }
});
})
});
<input type="radio" class="rbClassTemplateList" name="rbTemplateList" id="template1" value="1" />
<input type="radio" class="rbClassTemplateList" name="rbTemplateList" id="template2" value="2" />
...
...
$(".rbClassTemplateList").click(function() {
...
<input type='radio' name='rbTemplateList' id='template1" value="1" />
<input type='radio' name='rbTemplateList' id='template3" value="3" />
<input type='radio' name='rbTemplateList' id='template5" value="5" />
<input type='radio' name='rbTemplateList' id='template7" value="7" />
...
$("input[name='rbTemplateList']").click(function() {
...
<input type='radio' name='rbTemplateList' id='template1" value=1 >
<input type='radio' name='rbTemplateList' id='template1' value='1'>