<html>
<head>
<meta charset="UTF-8" />
<title>test</title>
<script>
var sel = function(s){
if(s.children[s.selectedIndex].innerHTML.replace(/^[\r\n\f\t\x20]+|[\r\n\f\t\x20]+$/g,"")=="其他"){
var inp = document.createElement("input")
inp.type = "text"
inp.placeholder="赶快输入"
inp.id = "inp"
document.body.appendChild(inp)
alert("输入")
}else{
var inp = null
if(!!(inp=document.getElementById("inp"))){
inp.outerHTML = ""
}
}
}
</script>
</head>
<body>
<select onchange = "sel(this)">
<option>sdf</option>
<option>其他</option>
</select>
</body>
<footer>
</footer>
</html>
值其实是赋上去了,不信你可以选中options[0]然后获取这个select的value其实option有两个东西,一个是value,一个是显示的字符串,比如:
<option value="name">张三</option>,你取这个元素的value得到的是“name”,而取innerHTML得到的是“张三”,所以你光改value是看不到变化的,还要改innerHTML属性.
document.getElementById("st_zm").options[0].value = this.responseText
document.getElementById("st_zm").options[0].innerHTML = this.responseText
为<html:select>定义id属性,然后在JS中使用document.getElementById("")就可以对他进行 *** 作了~比如你要做赋值,可以这么写~
<html:select id="test"></html:select>
<script>
document.getElementById("test").value="1"
</script>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)