谁能帮我在这个加个验证,也就是说如果listbox2里有了,listbox1点的时候就出个对话框提示一下,并且不把选中的值放到listbox2中(相当于就弹个框,别的操作不做)
function SelectOne()
{
var lst1=window.document.getElementById( "ListBox1 ");
var lstindex=lst1.selectedIndex;
if(lstindex <0)
return;
var v = lst1.options[lstindex].value;
var t = lst1.options[lstindex].text;
var lst2=window.document.getElementById( "ListBox2 ");
var option_ = document.createElement( "option ");
lst2.add(option_);
option_.value=v;
option_.innerHTML=t;
}
------解决方案--------------------------------------------------------
var lst2=window.document.getElementById( "ListBox2 ");在这后面加一个for(var i=0;i <lst2.options.length;i++){ if(lst2.options[i].value == v) { alert( "已经存在! "); return; }}
------解决方案--------------------------------------------------------
function isinlist(name)
{
var i = 0;
for (i; i < lst2.length; i++)
{
if (lst2[i].value == name)
{
return true;
}
}
return false;
}
------解决方案--------------------------------------------------------
for eahc(lst1)
{
for(var i=0;i <lst2.options.length;i++)
{
if(lst2.options[i].value == v)
{
alert( "已经存在! "); return;
}
}
}
------解决方案--------------------------------------------------------
function SelectOne()
{
var lst1=window.document.getElementById( "ListBox1 ");
var lstindex=lst1.selectedIndex;
if(lstindex <0)
return;
var v = lst1.options[lstindex].value;
var t = lst1.options[lstindex].text;
var lst2=window.document.getElementById( "ListBox2 ");
for (i=0; i < lst2.length; i++)
{
if (lst2[i].value == v)
{
alert( '选择已选择! ');
return;
}
}
var option_ = document.createElement( "option ");
lst2.add(option_);
option_.value=v;
option_.innerHTML=t;
}