最近在用jquery each做了一个关于单项选择题的验证,代码如下
jQuery.each(jQuery("div#select"),function(i,item){
selected=0;
jQuery.each(jQuery(item).find(":radio"),function(){
if(this.checked){selected++;}
});
if(selected<=0)
{
$(this).addClass("selectRad");
flag=false;
}
else
{
$(this).addClass("not");
}
});
遇到个奇怪的问题,我在本地测试的时候,each能够实现循环,但是当我将网页放在外网上就不能实现循环,只能读取一次,不知道是什么原因,请高手指点下
jQuery.each(jQuery("div#select"),function(i,item){
selected=0;
jQuery.each(jQuery(item).find(":radio"),function(){
if(this.checked){selected++;}
});
if(selected<=0)
{
$(this).addClass("selectRad");
flag=false;
}
else
{
$(this).addClass("not");
}
});
遇到个奇怪的问题,我在本地测试的时候,each能够实现循环,但是当我将网页放在外网上就不能实现循环,只能读取一次,不知道是什么原因,请高手指点下
jQuery.each(jQuery('div#select'),function (i,item){
alert("i=" + i );
});
html源代码:<div id="select">
<div class="Title">
<input type="hidden" name="rpQuestions$ctl01$hideQuestionId" id="rpQuestions_ctl01_hideQuestionId" value="1" />
一、您公司是否"投资"过网络推广服务?</div>
<div style="padding-left:20px;background-color:#f1f1f1; width:770px;">
<table id="rpQuestions_ctl01_radList" border="0">
<tr>
<td><input id="rpQuestions_ctl01_radList_0" type="radio" name="rpQuestions$ctl01$radList" value="A" /><label for="rpQuestions_ctl01_radList_0">A 是</label></td>
</tr><tr>
<td><input id="rpQuestions_ctl01_radList_1" type="radio" name="rpQuestions$ctl01$radList" value="B" /><label for="rpQuestions_ctl01_radList_1">B 否</label></td>
</tr>
</table></div></div>
<div style="width: 770px; height: 10px; line-height: 10px">
</div>
<div id="select">
<div class="Title">
<input type="hidden" name="rpQuestions$ctl02$hideQuestionId" id="rpQuestions_ctl02_hideQuestionId" value="2" />
二、您公司希望通过网络推广起到哪些作用
</div>
<div style="padding-left:20px;background-color:#f1f1f1; width:770px;">
<table id="rpQuestions_ctl02_radList" border="0">
<tr>
<td><input id="rpQuestions_ctl02_radList_0" type="radio" name="rpQuestions$ctl02$radList" value="A" /><label for="rpQuestions_ctl02_radList_0">A 提升企业形象</label></td>
</tr><tr>
<td><input id="rpQuestions_ctl02_radList_1" type="radio" name="rpQuestions$ctl02$radList" value="B" /><label for="rpQuestions_ctl02_radList_1">B 品牌传播</label></td>
</tr><tr>
<td><input id="rpQuestions_ctl02_radList_2" type="radio" name="rpQuestions$ctl02$radList" value="C" /><label for="rpQuestions_ctl02_radList_2">C 产品在线销售</label></td>
</tr>
</table></div></div>
正常现象应该是:每循环一个div为select就弹出序号,
不正常现象:在本地测试能够正常循环,放在网上就只能循环一次请高手指点啊
alert("i=" + i );
});改成jQuery.each(jQuery('div[name=select]'),function (i,item){
alert("i=" + i );
});
试试。
jQuery.each(jQuery('div[id=select]'),function (i,item){
alert("i=" + i );
});
比如
<input id="test" value="测试1"></input>
<input id="test" value="测试2"></input>
用$('#test').length //1
$('input[id="test"]').length //2
至于外网内网,我也是跟你一样不知道啊。