日期:2014-05-16 浏览次数:20464 次
function addRcvUser(userid,userenname) { var textarea=document.getElementById("managertextarea"); var oldTextarea=textarea.innerHTML; if(oldTextarea.trim()=="") { textarea.innerHTML=userenname; }else textarea.innerHTML=oldTextarea+" , "+userenname; var receiver=document.getElementById("receiver"); receiver.value=userid; }
<select size=20> <%for(int i=0;i<size;i++){%> <option value="<%=users.get(i).getUserid()%>" id="selected_<%=users.get(i).getUserid()%>" onclick="addRcvUser(<%=users.get(i).getUserid()%>,'<%=users.get(i).getUserrename() %>')"> <%=users.get(i).getUserrename() %> </option> <%} %> </select>
<textarea name="managertextarea" id="managertextarea" cols="54" rows="4" readonly="readonly"> </textarea>
<select size=20 onchage="addRcvUser(this)"> <option value="<%=users.get(i).getUserid()%>" id="selected_<%=users.get(i).getUserid()%>"> <%=users.get(i).getUserrename() %> </option> </select> //函数修正 function addRcvUser(o) { var userid=o.value; var userenname=o.options[o.selectedIndex].text; var textarea=document.getElementById("managertextarea"); var oldTextarea=textarea.innerHTML; if(oldTextarea.trim()=="") { textarea.innerHTML=userenname; }else textarea.innerHTML=oldTextarea+" , "+userenname; var receiver=document.getElementById("receiver"); receiver.value=userid; }
------解决方案--------------------
或者加上
String.prototype.trim= function(){
// 用正则表达式将前后空格
// 用空字符串替代。
return this.replace(/(^\s*)|(\s*$)/g, "");
}