<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>無題のページ</title>
<script language="JavaScript" src="JScript.js"></script>
</head>
<body onload="setDrp();">
<select id="Select1" style="width: 296px" onmousedown ="repDrp();">
<option selected="selected"></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select></body>
</html>function setDrp() {
document.getElementById("Select1").options[0].innerHTML="<option selected='selected' value='123'>123</option>";}function repDrp() {document.getElementById("Select1").options[0].innerText="<option selected='selected' value=''></option>";document.getElementById("Select1").value="";}每次点击第一次 下拉框都出来 研究2天了
求助 有啥办法可以克服这个问题
<body onload="setDrp();">
<select id="Select1" style="width: 296px" >
<option selected="selected"></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select></body>function setDrp() {
document.getElementById("Select1").options[0].innerHTML="<option selected='selected' value='123'>123</option>";
document.getElementById("Select1").options[0].innerText="<option selected='selected' value=''></option>";document.getElementById("Select1").value="";
}
然后你鼠标点 下拉框弹出来的时候 变成 "" 2 3 4 这个1变成了"" 无任何项背选中
不要用先insert 然后在remove 这样的话会有个过度效果的 不好
所以我直接 重写 document.getElementById("Select1").options[0].innerText
但是这样就出现一个问题了 第一次点 后select中的项是改变了 但是下拉框却没出来
試試ondrop
function setDrp() {
document.getElementById("Select1").options[0].text="123";} function repDrp()
{
var obj = document.getElementById("Select1");
obj.options[0].text="";
}
</script>
这样试试
哈哈 效果很漂亮了 但是还有个很重要的问题 那就是 obj.options[0].text=“” 的同时 能不能把obj.options[0]的对应value值也改掉 比如改成999
那这样 最后就是点击下拉框后 Select1的第一项变成 text为“” 对应value为999
我来说原因 页面初始的时候 从库里读一条数据 这条数据中的某一项 比如是 A 是要显示到已经绑好数据的select上的
但是呢 绑好的select中没有要显示的这项A select中只有 B C D
所以呢 在初始的时候 还是要赋上去 鼠标去点下拉框的时候 再把下拉框中不存在的A抹去 关键是初始显示的时候 是啥就得显示啥最后保存的时候 那肯定是去保存这个selcet的选中vlaue值的啊 如果显示在select上的是不存在的 A 那么 进库的就是 A
否则就是其他 B C D 各自对应的 value不清楚再补充 我现在是继承了dropdownlist 然后基本上就打算在render中写js 来模拟
function repDrp()
{
var obj = document.getElementById("Select1");
obj.options[0].text="";
obj.options[0].value="999";
}
这样,不知道是不是你要的效果
代码<select id="Select1" name="Select1" style="width: 296px" onmousedown="this.options[0].text='';this.options[0].value='999'">
<option selected="selected" value="0">444</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<input type="button" onclick="alert(document.all.Select1.value)" value="show()" />