jerome66
jerome66
2015-07-26 22:37
采纳率: 46.7%
浏览 4.0k
已采纳

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("请选择联系人!");
}
});


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

5条回答 默认 最新

  • danielinbiti
    danielinbiti 2015-07-26 23:07
    已采纳
     <!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>
    
    
    点赞 评论
  • humeSnail
    humeSnail 2015-07-26 23:55

    点击的文本可以用this来表示

    点赞 评论
  • yuke198907
    yuke198907 2015-07-27 00:19

    或者你点击不同的按钮,执行不同的js函数呀

    点赞 评论
  • showbo

    打开窗体的时候传递控件的id值,在被打开也获取就行

     <script>
    
        function openNewccWindow(id) {
            window.open("<%=basePath%>user/showUserList.action#"+id, 'linkman', "width=260 ,height=345,top=200,left=" + ((window.screen.width / 2) - 200));
        }
    
        function openNewbccWindow(id) {
            window.open("<%=basePath%>user/showUserList.action#" + id, 'linkman', "width=260 ,height=345,top=200,left=" + ((window.screen.width / 2) - 200));
        }
    </script>
    <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('i_rescive');">添加</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('i_cc');">添加</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('i_bcc');">添加</a>
        </td>
    </tr>
    

    showUserList.action

      window.opener.document.getElementById(location.hash.substring(1)).value += tVal;
    
    点赞 评论
  • sina_2831808769
    sina_2831808769 2015-07-27 14:30
    点赞 评论

相关推荐