三個文本框的id分別為"i_rescive,"i_cc",i_bcc,怎麼在jsp中根據id判斷應該顯示在哪個文本框中,就是條件語句怎麼寫
window.opener.document.getElementById("i_rescive").value += tVal;
//顯示聯系人列表
//function showSendPage() {
function openNewWindow(){
window.open("<%=basePath%>user/showUserList.action",'linkman',"width=260 ,height=345,top=200,left="+((window.screen.width/2)-200));
}
function openNewccWindow(){
window.open("<%=basePath%>user/showUserList.action",'linkman',"width=260 ,height=345,top=200,left="+((window.screen.width/2)-200));
}
function openNewbccWindow(){
window.open("<%=basePath%>user/showUserList.action",'linkman',"width=260 ,height=345,top=200,left="+((window.screen.width/2)-200));
}
<tr>
<td class="label">發件人:</td>
<s:set var="alias" value="user.true"></s:set>
<%String name = ""; %>
<td><span class="person">
<s:if test='#alias!=null&&#alias!=""'>${alias}<%name="\""+pageContext.getAttribute("alias")+"\"<"+user.getName()+"@ljg.com>";%></s:if>
<s:else>"${user.name}"<%name="\""+user.getName()+"\"<"+user.getName()+"@ljg.com>";%></s:else><${user.name}@ljg.com>
</span>
<input type="hidden" name="mailInfoFB.from" value='<%=name %>' id="i_from"/>
</td>
<td align="right"><a href="javascript:bb()" id="acc">添加抄送</a> | <a href="javascript:cbb()" id="abcc">添加密送</a></td>
</tr>
<tr>
<td class="label">收件人:</td>
<td class="e_input" colspan="2"><textarea title="多個收件人請以分號(;)分隔" class="s_input" id="i_rescive" onfocus="inputfocus()" name="mailInfoFB.to"><s:property value="mailInfoFB.to"/></textarea>
<a href="javascript:;" id="tianjia" onclick="openNewWindow();">添加</a>
</td>
</tr>
<tr id="cc" style="display: none;">
<td class="label">抄送:</td>
<td class="e_input" colspan="2"><textarea title="多個抄送人請以分號(;)分隔" class="s_input" id="i_cc" onfocus="inputfocus()" name="mailInfoFB.cc"><s:property value="mailInfoFB.cc"/></textarea>
<a href="javascript:;" id="addcc" onclick="openNewccWindow();">添加</a>
</td>
</tr>
<tr id="bcc" style="display: none;">
<td class="label">密送:</td>
<td class="e_input" colspan="2"><textarea title="多個密送人請以分號(;)分隔" class="s_input" id="i_bcc" onfocus="inputfocus()" name="mailInfoFB.bcc"><s:property value="mailInfoFB.bcc"/></textarea>
<a href="javascript:;" id="addbcc" onclick="openNewbccWindow();">添加</a>
</td>
</tr>
以下是新窗口jsp中的內容
$().ready(function(){
$("#selectUserBtn").click(function(){
var data = [];
$("[name='cbUserName']:checked").each(function(){
data.push($(this).attr("value")+"@ljg.com");
});
var len = data.length;
if(len > 0){
var dataVal = '';
for(var i = 0;i <len;i++){
var tmp = data[i];
if(i<=len-1){
tmp += ";";
}
dataVal+=tmp;
}
var tVal = dataVal;
window.opener.document.getElementById("i_rescive").value += tVal;
window.close();
}else{
alert("請選擇聯系人!");
}
});
<!DOCTYPE html>
<html>
<script>
function btnClick(self){
if(self.id=='btn_rescive'){//正規的if判斷
document.getElementById('i_rescive').value='1';
}else{//兩種不同的條件運用方式,根據後綴一樣來獲取input的id
var str = self.id.replace('btn_','i_');
document.getElementById(str).value=str;
}
}
</script>
<body>
<div>
<input type='text' id='i_rescive'/>
<input type='text' id='i_cc'/>
<input type='text' id='i_bcc'/>
</div>
<div>
<input type='button' onclick="btnClick(this)" value='1' id='btn_rescive'/>
<input type='button' onclick="btnClick(this)" value='2' id='btn_cc'/>
<input type='button' onclick="btnClick(this)" value='3' id='btn_bcc'/>
</div>
</body>
</html>