日期:2014-05-18  浏览次数:20791 次

在线等问题,急请javascript高手过来看下!
我有一个问题,我这边有一个select框,想完成,从数据库里面动态的读出数据后,假设有1,2,3,4   个选择,当我选中2后,在边上有一个按钮实现添加,一个实现删除,将选中的2添加加一个input的文本框里面去,每个以逗号分开如2,3这样的!参考已经有的代码:选择框:已经完成从rs集里面读出所有数据到select的option里面
<select   name= "select3 ">
                        <%while(rs.next()){%>
                        <option   value= " <%=rs.getString( "Name ")%> "     > <%=rs.getString( "Name ")%>   </option>
                        <%}rs2.beforeFirst();%>
                    </select>

图片按钮,也可是一般的button按纽一个添加,一个删除
<img   src= "../images/添加.gif "   width= "15 "   height= "17 "   onclick= "add(); "/>  

<img   src= "../images/删除.gif "   width= "15 "   height= "17 "   onclick= "del(); "/>


文本框,用来在按添加按钮后,将select里面刚选的option添加进来:
<INPUT   name= "Headship "     value= " "     maxLength=50   >

现在需要写function   add()和del()     望高手指教!


如果朋友有看到过样网站的也请发一个我看看,谢谢!

在线等高手来!


------解决方案--------------------
<html>
<head>
<title> b </title>
</head>
<script language= "javascript ">

function add(){
var textValue = document.getElementById( "inputText ");
if (textValue.value != ' '){
textValue.value += ", " + document.getElementById( "s1 ").value;
}else{
textValue.value = document.getElementById( "s1 ").value;
}
}

function del(){
var textValue = document.getElementById( "inputText ");
if (textValue.value != ' '){
var a = textValue.value.split( ", ");
if (a != null){
if (a.length > 1){
textValue.value = a[0];
for(i=1;i <a.length-1;i++){
textValue.value += ", "+a[i];
}
}else{
textValue.value = ' ';
}
}
}
}

</script>
<body>

<input type= 'text ' id= 'inputText ' size=20 />
<select id=s1>
<option value=1> 1 </option>
<option value=2> 2 </option>
<option value=3> 3 </option>
<option value=4> 4 </option>
</select>
<input type= "button " value= "add "onclick= 'add() ' >
<input type= "button " value= "del "onclick= 'del() ' >
</body>
</html>

写的粗糙了点