使用select添加数据出错。
function Button1_onclick() {
alert(ListBox1.item[ "a "].text);
}
ListBox1的代码:
<select size= "4 " name= "ListBox1 " id= "ListBox1 " style= "width: 151px " >
<option value= "a "> a </option>
<option value= "b "> b </option>
<option value= "c "> c </option>
</select>
button的代码。
<input id= "Button1 " type= "button " value= "button " language= "javascript " onclick= "return Button1_onclick() " />
报错信息是:
'ListBox1.item.a.text '为空或不是对象
我将alert(ListBox1.item[ "a "].text);改成:
ListBox1.add( "F ");
报错:类型不匹配,错误代码为0;
请问要执行select如下功能要怎么做:
1:添加一行文本
2:查找一行文本跟指定的文本是否匹配(想sql语句中的 FieldName like '%FieldValue% ').
3:删除一条数据。
------解决方案--------------------一个脚本循环就成啊
------解决方案-------------------- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN ">
<html>
<head>
<title> New Document </title>
<meta name= "Generator " content= "EditPlus ">
<meta name= "Author " content= " ">
<meta name= "Keywords " content= " ">
<meta name= "Description " content= " ">
</head>
<body>
<script language= "javascript ">
function getPos(serC)
{
if (serC==null || !serC)
{
return -1;
}
var objlist=document.getElementById( "test ");
for (var i=0;i <objlist.options.length;i++ )
{
if(objlist.options[i].text.indexOf(serC)> =0)
{
return i;
break;
}
}
return -1;
}
</script>
<input type= "text " id= "txt " value= " " /> <input type= "button " onclick= "alert(getPos(txt.value)); " value= "go " />
<select id= "test ">
<option value= "dd "> a </option>
<option value= "dd "> b </option>
<option value= "dd "> c </option>
<option value= "dd "> d </option>
<option value= "dd "> ef </option>
<option value= "dd "> dfa </option>
<option value= "dd "> 测 </option>
<option value= "dd "> 量 </option>
<option value= "dd "> 大 </option>
</select>
</body>
</html>