<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 >我想单击其中的一个rbTemplateList,将引发ajax调用(jquery风格),但它根本不起作用…
我相信这与id和name属性有关
$(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(){ }
});
})
}); 发布于 2010-01-06 10:06:21
HTML将"name“改为"class”
<input type="radio" class="rbClassTemplateList" name="rbTemplateList" id="template1" value="1" />
<input type="radio" class="rbClassTemplateList" name="rbTemplateList" id="template2" value="2" />
...JS将#rbTemplateList改为".rbClassTemplateList“
...
$(".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" />JS:
...
$("input[name='rbTemplateList']").click(function() {
...发布于 2010-01-06 20:25:17
问题是您正在使用$("#rbTemplateList")将事件附加到单选按钮,但是开头的#引用元素的in,而rbTemplateList在html中是作为一个名称给出的。
您应该将选择器更改为$(":input[name='rbTemplateList']")
发布于 2010-01-06 10:08:50
您正在使用"# rbTemplateList“,它将引用rbTemplateList的id,但这是每个元素的名称。为简单起见,您可以为它们分配相同的类:
class=‘某些东西’
然后使用$(".something").click
https://stackoverflow.com/questions/2010485
复制相似问题