var ListUtil = new Object();
ListUtil.add = function (oListbox, sName, sValue) {
var oOption = document.createElement("option");
oOption.appendChild(document.createTextNode(sName));
if (arguments.length == 3) {
oOption.setAttribute("value", sValue);
}
oListbox.appendChild(oOption);
}
.....
for (var i = 1; i < 21; i++) {
ListUtil.add(Percent1, i * 5, i * 5);
}
Percent1.value = 10;
alert(Percent1.value); //显示为5而不是10用var oOption=new Option("test","test");可以,但是在火狐中无法正常运行。谢谢
ListUtil.add = function (oListbox, sName, sValue) {
var oOption = document.createElement("option");
oOption.appendChild(document.createTextNode(sName));
if (arguments.length == 3) {
oOption.setAttribute("value", sValue);
}
oListbox.appendChild(oOption);
}
.....
for (var i = 1; i < 21; i++) {
ListUtil.add(Percent1, i * 5, i * 5);
}
Percent1.value = 10;
alert(Percent1.value); //显示为5而不是10用var oOption=new Option("test","test");可以,但是在火狐中无法正常运行。谢谢
newopt.text = text;//text 是文本
new.value = value;//值
select.options.add(newopt);
oOption.appendChild(document.createTextNode(sName));
if (arguments.length == 3) {
oOption.setAttribute("value", sValue);
}
oListbox.appendChild(oOption);为什么不行
<head></head>
<body>
<select id='sel'>
<option value='test'> test</option>
</select>
<script type='text/javascript'>
var sel = document.getElementById('sel');
var newopt = document.createElement('option');
newopt.text = 'text';//text 是文本
newopt.value = 'value';//值
sel.options.add(newopt);</script>
</body>
</html>
上面代码在firefox 3.6 ie6 下,没有问题
<head></head>
<body>
<select id='sel'>
<option value='test'> test</option>
</select>
<script type='text/javascript'>
var sel = document.getElementById('sel');
var newopt = document.createElement('option');
newopt.text = 'text';//text 是文本
newopt.value = 'value';//值
//sel.options.add(newopt);
sel.appendChild(newopt);
</script>
</body>
</html>都没有问题
用 selectObj.selectedIndex = n 无论哪种情况都可以指定选中项,LZ可以考虑遍历比较value后再指定下拉列表的selectedIndex.
var tempMatch = new Array();
var tempNoMatch = new Array();
var count=0;
var =false;
function matchMoveselect(matchedId){
var matched = document.getElementById(matchedId);
var temp = new Array();
var j=0;
if(count==0){
for(i=0;i<matched.options.length;i++){
tempMatch[i]=new Option(matched.options[i].text,matched.options[i].value);
}
}
count++;
for(i=0;i<matched.options.length;i++){
if(matched.options[i].selected){
=true;
//noMatched.options[noMatched.options.length]=new Option(matched.options[i].text,matched.options[i].value);
temp[j]=i;
j++;
}
}
for(i=0;i<=temp.length;i++) {
matched.options[temp[i]-i]=null;
}
}</script>/*添加select模板参考var sAgent = navigator.userAgent.toLowerCase() ;
// Internet Explorer
if ( sAgent.indexOf("msie") != -1 && sAgent.indexOf("mac") == -1 && sAgent.indexOf("opera") == -1 )
{
if(flag){
var sleold=oldstr.options.length;
var slenew=vect.size();
oldstr.options.length=0;
for(var i=0;i<slenew;i++){
var moPtion=window.opener.document.createElement("OPTION");
moPtion.text=map.get(vect.get(i));
moPtion.value=vect.get(i);
if(!oldstr.contains(moPtion)){
oldstr.add(moPtion);
}
}
}
}else{
if(flag){
var slenew=vect.size();
for(var i=0;i<slenew;i++){
oldstr.options[i]=new Option(map.get(vect.get(i)),vect.get(i));
}
}
}*/end<select name="signatory" ondblclick="matchMoveselect('selFile');" multiple="multiple" style="width:300" id="selFile"><option value="100">Winston ,</option></select>
<input name="rightMove" type="button" class="button"
value="Remove" onClick="matchMoveselect('selFile');">