我有一个要求,我根据JSON响应动态创建单选按钮。到目前为止,我在Chrome和firefox中的工作,但给出对象不支持此属性或方法 if(subItem [1] .indexOf (,)> = 0) line
我的代码 = 0) { var tLis T = temp.split( ); $ .each(tList,function(k,val){ if(configCount == 0) { c1Svc.push(val); } else { c2Svc.push(val); } }); } else { if(configCount == 0) { c1Svc.push(subItem [1]); } else { c2Svc.push(subItem [1]); } } configCount ++; }); } }); if($(#customServiceListing)。length == 0) { $(#compareContent)。append('< table id =customServiceListing align =centerwidth =90%class =csm-tableborder =1>< tbody>< tr>< td>< form id =c1Service>< / form>< / td>< td>< form id =c2Service>< / form>< / td>< / tr>< / tbody>< / table>'); } else { $('#c1Service')。empty(); $('#c2Service')。empty(); } } else { $(#compareContent)。append('< table align =centerwidth = 90%class =csm-tableborder =1>< tbody>< tr>< td>< form>< select id =c1Service>< / select>< / form>< / td>< td>< select id =c2Service>< / select>< / td>< td>< select id =c3Service>< / select> ;< / TD>< / TR>< / tbody的>< /表>'); $ b $ *将服务收音机添加到config1 * / $ .each(c1Svc,function(i,item){ $( #c1Service)。append('< input type =radioname =customConfig1ServiceNamesid ='+ item +'value ='+ i + 1 +'/>'+ item); }); if(c1Svc.length> 1) $(#c1Service)。append('< br />'); $ b $ * *将服务收音机添加到config2 * / $ .each(c2Svc,function(i,item){ $(#c2Service)。append('< ; input type =radioname =customConfig2ServiceNamesid ='+ item +'value ='+ i + 1 +'/>'+ item); }); if(c2Svc.length> 1) $(#c2Service)。append('< br />'); });
更新
这里是各种列表IE8不支持的功能代码
更新 这里有什么问题,它给我的每个值 -1 我使用Sudhir给出的代码 $ b alert(subItem [1] .indexOf(, )+,+ subItem [1]);
截图
更新
在这里, var temp = subItem [1] .toString(); ,将它转换为String工作。
解决方案IE版本< 9没有 indexOf ,所以你可以添加你自己的:
if(!Array.prototype.indexOf){ Array.prototype.indexOf = function(elt / *,from * /){ var len = this.length>>> 0; var from = Number(arguments [1])|| 0; from =(from <0)? Math.ceil(from):Math.floor(from); if(from <0)from + = len; (从< len; from ++){ if(from this&& this [from] === elt)返回; } 返回-1; };var subItem = []; subItem [1] =CSMTestPWXListinerService,CSMTestPWXListinerService_ManualyAdded; console.log(subItem [1] .indexOf(,)); //返回25
I have a requirement where I create radio buttons dynamically based upon JSON response. So far what I did works in Chrome and firefox, but gives Object doesn't support this property or method on if(subItem[1].indexOf(",") >= 0) line
My code
$("#sList").live("change", function(){ var currentService=this.value; var c1Svc=[]; var c2Svc=[]; if(absP.length==2) { $.each(compareServiceData,function(i,item){ if(currentService==item[0]) { var configCount=0; $.each(item[1],function(j,subItem){ var temp=subItem[1]; /*The JSON response contains List of Lists, so here if it contains a list it will be separated by "," so split it and store in a array, else directly store in a array*/ if(subItem[1].indexOf(",") >= 0) { var tList=temp.split(","); $.each(tList,function(k,val){ if(configCount==0) { c1Svc.push(val); } else { c2Svc.push(val); } }); } else { if(configCount==0) { c1Svc.push(subItem[1]); } else { c2Svc.push(subItem[1]); } } configCount++; }); } }); if ($("#customServiceListing").length == 0) { $("#compareContent").append('<table id="customServiceListing" align="center" width="90%" class="csm-table" border="1"><tbody><tr><td><form id="c1Service"></form></td><td><form id="c2Service"></form></td></tr></tbody></table>'); } else { $('#c1Service').empty(); $('#c2Service').empty(); } } else { $("#compareContent").append('<table align="center" width="90%" class="csm-table" border="1"><tbody><tr><td><form><select id="c1Service"></select></form></td><td><select id="c2Service"></select></td><td><select id="c3Service"></select></td></tr></tbody></table>'); } /*adding service radios to config1*/ $.each(c1Svc,function(i,item){ $("#c1Service").append('<input type="radio" name="customConfig1ServiceNames" id="'+item+'" value="'+i+1+'"/>'+item); }); if(c1Svc.length>1) $("#c1Service").append('<br/>'); /*adding service radios to config2*/ $.each(c2Svc,function(i,item){ $("#c2Service").append('<input type="radio" name="customConfig2ServiceNames" id="'+item+'" value="'+i+1+'"/>'+item); }); if(c2Svc.length>1) $("#c2Service").append('<br/>'); });Update
Here is a List of various function code not supported by IE8
Update What is the problem here, for every value it gives me -1 I am using code given by Sudhir
alert(subItem[1].indexOf(",")+", "+subItem[1]);
Screenshot
Update
Got it here, var temp=subItem[1].toString(); was the problem, converting it to String worked.
解决方案IE versions < 9 don't have indexOf, so you can add your own:
if (!Array.prototype.indexOf) { Array.prototype.indexOf = function (elt /*, from*/) { var len = this.length >>> 0; var from = Number(arguments[1]) || 0; from = (from < 0) ? Math.ceil(from) : Math.floor(from); if (from < 0) from += len; for (; from < len; from++) { if (from in this && this[from] === elt) return from; } return -1; }; }var subItem = []; subItem[1]="CSMTestPWXListinerService,CSMTestPWXListinerService_ManualyAdded"; console.log(subItem[1].indexOf(",")); //returns 25
更多推荐
在IE 8中不支持indexOf?
发布评论