<SCRIPT LANGUAGE="JavaScript">
<!--
function addItem()
{
var txt=document.all("txt").value;
if(txt!="")
{
var group = document.createElement('OPTGROUP');
// group.label = document.all.mySelect.length + 1;
// document.all.mySelect.appendChild(group);
var opt = new Option(txt,txt);
document.all.mySelect.add(opt)
opt.selected;
document.all.txt.value='';
}
else
{
alert("You must write something!");
}
}
function delItem()
{
mySelect.remove(mySelect.selectedIndex)
}
function upItem()
{
var index = mySelect.selectedIndex;
if(index != 0)
{
var tempVal = mySelect.options[index].value;
var tempText = mySelect.options[index].text;
mySelect.options[index].value = mySelect.options[index-1].value;
mySelect.options[index].text = mySelect.options[index-1].text;
mySelect.options[index-1].value = tempVal;
mySelect.options[index-1].text = tempText;
mySelect.options[index-1].selected = true;
}
}
function downItem()
{
var index = mySelect.selectedIndex;
if(index != mySelect.options.length-1)
{
var tempVal = mySelect.options[index].value;
var tempText = mySelect.options[index].text;
mySelect.options[index].value = mySelect.options[index+1].value;
mySelect.options[index].text = mySelect.options[index+1].text;
mySelect.options[index+1].value = tempVal;
mySelect.options[index+1].text = tempText;
mySelect.options[index+1].selected = true;
}
}
//-->
</SCRIPT>
</HEAD><BODY>
<select name="mySelect" size="18" id="mySelect" class="ddlEnable" >
<optgroup >
<option value="1">item1</option> <option value="2">item2</option> <option value="3">item3</option> <option value="4">item4</option>
</optgroup>
</select>
<input type="button" id="btnUpdata" value="上移" onclick="upItem()" /><input type="button" value="下移" onclick="downItem()" /><input type="button" id="btnUpdata" value="删除" onclick="delItem()" />
<br/>
<input type="text" size=68 name="txt" id="txt" class="txtReadonly" />
<input type="button" name="btnUpdata" id="btnUpdata" value="add" onclick="addItem();" />
</HTML>
<!--
function addItem()
{
var txt=document.all("txt").value;
if(txt!="")
{
var group = document.createElement('OPTGROUP');
// group.label = document.all.mySelect.length + 1;
// document.all.mySelect.appendChild(group);
var opt = new Option(txt,txt);
document.all.mySelect.add(opt)
opt.selected;
document.all.txt.value='';
}
else
{
alert("You must write something!");
}
}
function delItem()
{
mySelect.remove(mySelect.selectedIndex)
}
function upItem()
{
var index = mySelect.selectedIndex;
if(index != 0)
{
var tempVal = mySelect.options[index].value;
var tempText = mySelect.options[index].text;
mySelect.options[index].value = mySelect.options[index-1].value;
mySelect.options[index].text = mySelect.options[index-1].text;
mySelect.options[index-1].value = tempVal;
mySelect.options[index-1].text = tempText;
mySelect.options[index-1].selected = true;
}
}
function downItem()
{
var index = mySelect.selectedIndex;
if(index != mySelect.options.length-1)
{
var tempVal = mySelect.options[index].value;
var tempText = mySelect.options[index].text;
mySelect.options[index].value = mySelect.options[index+1].value;
mySelect.options[index].text = mySelect.options[index+1].text;
mySelect.options[index+1].value = tempVal;
mySelect.options[index+1].text = tempText;
mySelect.options[index+1].selected = true;
}
}
//-->
</SCRIPT>
</HEAD><BODY>
<select name="mySelect" size="18" id="mySelect" class="ddlEnable" >
<optgroup >
<option value="1">item1</option> <option value="2">item2</option> <option value="3">item3</option> <option value="4">item4</option>
</optgroup>
</select>
<input type="button" id="btnUpdata" value="上移" onclick="upItem()" /><input type="button" value="下移" onclick="downItem()" /><input type="button" id="btnUpdata" value="删除" onclick="delItem()" />
<br/>
<input type="text" size=68 name="txt" id="txt" class="txtReadonly" />
<input type="button" name="btnUpdata" id="btnUpdata" value="add" onclick="addItem();" />
</HTML>
解决方案 »
- 请教个关于img.src相对路径的问题
- 仿58的搜索提示功能问题
- jquery chrome浏览器下怎么获取图片的宽度跟高度?
- 在线,求正则表达式!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 请教获取表格中的满足条件的某二行的正则表达式?具体内容请进...
- 什么错误?
- 急急!!如何把小数转换成百分数,有没有什么方法??
- 如何判断一个对象的种类?比如是select或者input
- 100分高手请指教:Netscape4.X和javascript难题!
- 如何用javascript求的ip地址
- 一个parent div中包含一个child div,在parent中设置innerText属性后,child div显示不出来了,有什么办法
- 如何在用javascript实现在新的窗口中打开网页
<head>
<SCRIPT LANGUAGE="JavaScript">
<!--
// code by meixx(梅雪香)
function addItem()
{
var txt = document.getElementById("txt");
var val = txt.value;
if(val == ""){
alert("You must write something!");
return;
}
var opt = document.createElement("OPTION");
opt.value = opt.text = val;
document.getElementById("mySelect").options.add(opt);
opt.selected = true;
txt.value = "";
}
function moveUpOrDown(flag){
var dlt = document.getElementById("mySelect");
var idx = dlt.selectedIndex;
if(idx < 0 ){ return;}
var newidx = idx + flag;
if(newidx < 0 || newidx >= dlt.options.length){ return ;}
dlt.options[idx].swapNode(dlt.options[newidx]);
}function rmOpt(){
var dlt = document.getElementById("mySelect");
var idx = dlt.selectedIndex;
if(idx < 0 ){ return;}
dlt.remove(idx);
}//-->
</SCRIPT>
</HEAD><BODY>
<select name="mySelect" size="18" id="mySelect" class="ddlEnable" >
<optgroup >
<option value="1">item1</option>
<option value="2">item2</option>
<option value="3">item3</option>
<option value="4">item4</option>
</optgroup>
</select>
<input type="button" value="上移" onclick="moveUpOrDown(-1)"/>
<input type="button" value="下移" onclick="moveUpOrDown(1)"/>
<input type="button" value="删除" onclick="rmOpt()"/>
<br/>
<input type="text" size="68" name="txt" id="txt" class="txtReadonly" />
<input type="button" name="btnUpdata" id="btnUpdata" value="add" onclick="addItem();" />
</body>
</HTML>