程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> javascript-js怎麼根據點擊的按鈕不同,在不同的文本框中顯示內容(jsp中寫條件語句)

javascript-js怎麼根據點擊的按鈕不同,在不同的文本框中顯示內容(jsp中寫條件語句)

編輯:編程綜合問答
js怎麼根據點擊的按鈕不同,在不同的文本框中顯示內容(jsp中寫條件語句)

三個文本框的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")+"\"&lt;"+user.getName()+"@ljg.com&gt;";%></s:if>
            <s:else>"${user.name}"<%name="\""+user.getName()+"\"&lt;"+user.getName()+"@ljg.com&gt;";%></s:else>&lt;${user.name}@ljg.com&gt;
        </span>
        <input type="hidden" name="mailInfoFB.from" value='<%=name %>' id="i_from"/>
    </td>
    <td align="right"><a href="javascript:bb()" id="acc">添加抄送</a>&nbsp;|&nbsp;<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>

jerome66
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved