JS为Select添加option ajaxselectjs前端 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 干嘛不用jquery 几句话解决 var selectSecond = $("#SelectSecond");修改为var selectSecond = $("#<%=SelectSecond.ClientID %>"); function createTag(parentTagId, childTag){ var thisObj=document.createElement(childTag); var parent =document.getElementById(parentTagId); parent.appendChild(thisObj); return thisObj;}........if (data) { var jsonObject=eval("("+data.Table+")"); //转换返回的josn数组,使其变为可操作对象 var selectSecond = $("#SelectSecond"); selectSecond.empty(); for(var obj in jsonObject){ var createObj = createTag('SelectSecond', 'option'); createObj.innerHTML = obj; createObj.value = jsonObject[obj]; }} selectSecond.options.add(Opt);应该改为selectSecond.options.add(Opt, null); 运行的时候 这里出错 var jsonObject=eval("("+data.Table+")"); Microsoft JScript 运行时错误: 缺少 ']' 楼主用的浏览器不是IE吧,slect添加option应该这样写: try { selectSecond.options.add(Opt, null); // standards compliant } catch(ex) { selectSecond.options.add(Opt); // IE only } } 我用的就是IE selectSecond.options在这里 提示获取不到 options这属性啊undefined 推荐jquery直接append就可以了,不用这么麻烦 <select id="SelectSecond" onchange="selected()"></select><select id="SelectSecond1" onchange="selected()"></select><script>//模拟数据d = [ {numbers:1, notects:'a'}, {numbers:2, notects:'b'}, {numbers:3, notects:'c'}];//jquery 写法$.each(d, function(i, t) {$("<option value='"+t.numbers+"'>"+t.notects+"</option>").appendTo($('#SelectSecond'));});//js 写法for(i=0; i<d.length; i++) { o = new Option(d[i].notects, d[i].numbers); document.getElementById('SelectSecond1').options[i] = o;}</script> 我用的就是IE selectSecond.options在这里 提示获取不到 options这属性啊undefined不好意思,我写错了,应该是 try { selectSecond.add(Opt, null); // standards compliant } catch(ex) { selectSecond.add(Opt); // IE only } }你再试试,绝对可以的。 其实就是你的 selectSecond.options.add(Opt); 这句话里多了options js判断是否安装pdf javascript高手请进!!` [求助]如果控制用<EMBED>嵌入的Flash文件的被点击后的操作? 数值计算的问题 js新手求助 很简单,很简单!但我不会呀,请老大帮帮忙,就是字符串与ASCII的转换! 简单!送分!-->如何批定义变量 如何实现网页中嵌入的realplay(或media player)在进行视频播放时根据播放的帧数产生网页的动态改变??? javascript和applet的通信问题,在线等待!! 如何让<option>里显示图片和动画 关于JQUERY在IE6下的bug问题 extjs中的thiz指的是什么呢?
var selectSecond = $("#SelectSecond");修改为
var selectSecond = $("#<%=SelectSecond.ClientID %>");
function createTag(parentTagId, childTag){
var thisObj=document.createElement(childTag);
var parent =document.getElementById(parentTagId);
parent.appendChild(thisObj);
return thisObj;
}
........
if (data) {
var jsonObject=eval("("+data.Table+")"); //转换返回的josn数组,使其变为可操作对象
var selectSecond = $("#SelectSecond");
selectSecond.empty();
for(var obj in jsonObject){
var createObj = createTag('SelectSecond', 'option');
createObj.innerHTML = obj;
createObj.value = jsonObject[obj];
}
}
Microsoft JScript 运行时错误: 缺少 ']'
{
selectSecond.options.add(Opt, null); // standards compliant
}
catch(ex)
{
selectSecond.options.add(Opt); // IE only
}
}
selectSecond.options在这里 提示获取不到 options这属性啊undefined
<select id="SelectSecond1" onchange="selected()"></select>
<script>
//模拟数据
d = [
{numbers:1, notects:'a'},
{numbers:2, notects:'b'},
{numbers:3, notects:'c'}
];//jquery 写法
$.each(d, function(i, t) {
$("<option value='"+t.numbers+"'>"+t.notects+"</option>").appendTo($('#SelectSecond'));
});//js 写法
for(i=0; i<d.length; i++) {
o = new Option(d[i].notects, d[i].numbers);
document.getElementById('SelectSecond1').options[i] = o;
}
</script>
selectSecond.options在这里 提示获取不到 options这属性啊undefined
不好意思,我写错了,应该是 try
{
selectSecond.add(Opt, null); // standards compliant
}
catch(ex)
{
selectSecond.add(Opt); // IE only
}
}
你再试试,绝对可以的。