javascript能否做到直接将字符串插入到select里面去啊 javascript能否做到直接将字符串插入到select里面去啊,比如以下代码,我希望加入到select中,谢谢function ddd(){ var option='<option value='ddd'>aaaa</option>';} 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不用这么写var y=document.createElement('option');y.text='Kiwi';y.value='hello';var x=document.getElementById("mySelect"); try { x.add(y,null); // standards compliant } catch(ex) { x.add(y); // IE only } $("#selectid").append("<option value='ddd'>'aaaa'</option>"); TRY:<html><head><script type="text/javascript">function insertOption() { var y=document.createElement('option'); y.text='Kiwi' y.value='11'; var x=document.getElementById("mySelect"); try { x.add(y,null); // standards compliant } catch(ex) { x.add(y); // IE only } }</script></head><body><form><select id="mySelect"> <option>Apple</option> <option>Pear</option> <option>Banana</option> <option>Orange</option></select><input type="button" onclick="insertOption()" value="Insert option" /></form></body></html> var selectElement = document.getElementById('node');//先取到select nodevar option = document.createElementt('option');//创建插入节点option.innerHTML = 'XXX';//添加内容selectElement.appendChild(option);//插入到select node中 <select id="s"></select>请输入要插入的合法字串:<input type="text" id="opt" value="<option value='ddd'>aaaa</option>" /><input type="button" value="add" onclick="add();" /><script text="text/javascript">function add(){ try{ document.getElementById("s").innerHTML = document.getElementById("s").innerHTML + document.getElementById("opt").value; } catch(e){ alert(e); }}</script> $("<option value='test'>test</option>").append("");document.createElement("");innerText="";.value="";appendChild(); 我来个另类的:$('<option value='ddd'>aaaa</option>').appendTo($('yourselectName')); 大神过来看看!!两个js冲突,求解救!!!!! 求一正则表达式 我原意出500元购买 DhtmlXgrid 1.2 Professional version.或者1.1也可以 请看看为什么会出错! execCommand('CreateLink',true, 'http://www.www.www/123.htm') 的一个问题 我想要类似模式对话框加最大化功能的代码 请问大虾们 关于prototype问题 怎么做到两张图片形成按钮效果..............急 javascript的问题 js子页面操作父页面 注入js,起调试作用,有没有?
var y=document.createElement('option');
y.text='Kiwi';
y.value='hello';
var x=document.getElementById("mySelect");
try
{
x.add(y,null); // standards compliant
}
catch(ex)
{
x.add(y); // IE only
}
<head>
<script type="text/javascript">
function insertOption()
{
var y=document.createElement('option');
y.text='Kiwi'
y.value='11';
var x=document.getElementById("mySelect");
try
{
x.add(y,null); // standards compliant
}
catch(ex)
{
x.add(y); // IE only
}
}
</script>
</head>
<body><form>
<select id="mySelect">
<option>Apple</option>
<option>Pear</option>
<option>Banana</option>
<option>Orange</option>
</select>
<input type="button" onclick="insertOption()" value="Insert option" />
</form></body>
</html>
var option = document.createElementt('option');//创建插入节点
option.innerHTML = 'XXX';//添加内容
selectElement.appendChild(option);//插入到select node中
</select>
请输入要插入的合法字串:<input type="text" id="opt" value="<option value='ddd'>aaaa</option>" />
<input type="button" value="add" onclick="add();" />
<script text="text/javascript">
function add(){
try{
document.getElementById("s").innerHTML = document.getElementById("s").innerHTML + document.getElementById("opt").value;
}
catch(e){
alert(e);
}
}
</script>
innerText="";
.value="";
appendChild();
$('<option value='ddd'>aaaa</option>').appendTo($('yourselectName'));