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

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 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>
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的