jsp页面动态加载form标签的action地址和里面的submit按钮事件

来源:互联网 发布:淘宝办电工证是真的吗 编辑:程序博客网 时间:2024/06/05 04:55

js里面

<script type="text/javascript">

         $("document").ready(function() {
                $('#btnSearch').live("click", function() {
                    $('#formID').attr("action", "term_showAll.shtml");
                    $('#formID').attr("method", "post");
                    $('#formID').submit();
                });
            });

</script>

html里面

<form id="formID">

    <input id="btnSearch" type="button" class="bt01" value="搜 索" name="" />

</form>


下面是整张jsp页面的例子

<%@ page language="java" import="java.util.*"
    contentType="text/html; charset=UTF-8" isELIgnored="false"
    pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>总部后台系统</title>
        <%@include file="/include/root_common.jsp"%>
        <script type="text/javascript">

            /*
             搜索按钮提交
             */
            $("document").ready(function() {
                $('#btnSearch').live("click", function() {
                    $('#formID').attr("action", "term_showAll.shtml");
                    $('#formID').attr("method", "post");
                    $('#formID').submit();
                });
            });
            

            /*
              导出按钮提交

            $("document").ready(function(){
               $('#btnExcel').live("click",function(){
                    $('#formID').attr("action","term_showToExcel.shtml");
                    $('#formID').attr("method","post");
                    $('#formID').submit();
               });
            });
             */
            function test1(value) {
                 $("#dealer").find("option:not(:first)").remove();
                $.post("term_searchTagency.shtml", {
                    "branchID" : $("#branch").val(),
                    "type" : "banch",
                    "status" : $("#status").val()
                }, function(data) {
                    $('#agency').find("option:not(:first)").remove()
                    //$('#agency').empty();   //清空resText里面的所有内容
                    var html = "";
                    /* var xxx=eval(data);  取值方法
                    for(var i=0;i<xxx.length;i++){                          
                      html+="<option value=\""+xxx[i].agencyID+"\">"+xxx[i].agencyName+"</option>";
                     }  
                    alert(html); */
                    var html = "";
                    var jsonObj = eval("(" + data + ")");
                    $.each(jsonObj, function(i, item) {
                        //alert(item.agencyID + ","  + item.agencyName);
                        html += "<option value=\""+item.agencyID+"\">"
                                + item.agencyName + "</option>";
                    });
                    $("#agency").append(html);
                    //alert(html);
                });
            };
            function test2(value) {
                $.post("term_searchTagency.shtml", {
                    "agencyID" : $("#agency").val(),
                    "type" : "agen",
                    "status" : $("#status").val()
                }, function(data2) {
                    //alert(data)
                    $('#dealer').find("option:not(:first)").remove();
                    var dealers = "";
                    var obj = eval("(" + data2 + ")");
                    $.each(obj, function(i, item2) {
                        //alert(item2.dealderID + ","  + item2.dealerName);
                        dealers += "<option value=\""+item2.dealderID+"\">"
                                + item2.dealerName + "</option>";
                    });
                    $("#dealer").append(dealers);
                    //alert(html);
                });
            };
        </script>
    </head>

    <body>
        <!--顶部开始-->
        <%@include file="/include/root_top.jsp"%>
        <!--顶部结束-->

        <!--主要部分开始-->
        <div class="mauto wbox bgwhite">
            <!--start left-->
            <%@include file="/include/root_left.jsp"%>
            <!--end left-->

            <!--start right-->
            <div class="ht_right fl t-aligL pb15">
                <!--start common right -->
                <%@include file="/include/root_right.jsp"%>
                <!--end common right -->
                <p class="ht_location f12">
                    您的位置:
                    <span class="green2"><a href="javascript:void(0);"
                        target="_self">终端管理</a> </span> > 终端列表
                </p>
                <div class="clear"></div>

                <!--列表开始-->
                <div class="ht_mainBox">
                    <div class="ht_search">
                        <form id="formID"><%--
                            终端号:
                            <input type="text" style="width: 100px;" name="termNo"
                                value="${termNo }" />
                                
                            &nbsp;&nbsp;
                            --%>
                            POS生产序列号
                            <input type="text" style="width: 100px;" name="fsn"
                                value="${fsn }" />
                            &nbsp;&nbsp;
                            状态:
                            <select name="status" >
                                    <option value="">
                                        所有
                                    </option>
                                <s:iterator value="statusMap" var="tmp">
                                    <option value="${tmp.key}" <s:if test="status ==#tmp.key">selected="selected"</s:if>  >
                                        ${tmp.value}
                                    </option>
                                </s:iterator>
                            </select>
                            &nbsp;&nbsp;
                            <input id="btnSearch" type="button" class="bt01" value="搜 索" name="" />
                            &nbsp;&nbsp;
                            <input type="button"  onclick="javascript:window.location.href='term_importFile.shtml'" title="导入文件"
                            class="bt01" value="导入文件" />
                            &nbsp;&nbsp;
                            <input type="button"  onclick="javascript:window.location.href='term_add.shtml'" title="导入文件"
                            class="bt01" value="添加序列号" /><br/>
                            
                            分公司:
                            <select name="branchID"  onchange="test1(this.value)" id="branch">
                                    <option value="">
                                        所有
                                    </option>
                                <s:iterator value="branchCompanyList" var="branch">
                                    <option value="${branch.fid}" <s:if test="branchID==#branch.fid">selected="selected"</s:if>  >
                                        ${branch.fname}
                                    </option>
                                </s:iterator>
                            </select>
                            &nbsp;&nbsp;
                            代理商:
                            <select name="agencyID" id="agency"  onchange="test2(this.value)" style="width:120px" >
                                    <option value="">
                                        所有
                                    </option>
                            </select>
                            &nbsp;&nbsp;
                            经销商:
                            <select  name="tdealerID" id="dealer"  onchange="test3(this.value)"  style="width:120px">
                                    <option value="">
                                        所有
                                    </option>                
                            </select>
                            &nbsp;&nbsp;
                            <input  type="button" title="终端下发" value="下发终端" class="bt01" id="setTerm"/>
                            </form>
                        </div>
                
                    <table width="100%" cellspacing="0" cellpadding="0" border="0"
                        class="table01 mt10 mb10 t-aligC">
                        <thead>
                            <tr>
                                <th> POS生产序列号 </th>
                                <th> 商户 </th>
                                <th> 商户号 </th>
                                <th> 状态 </th>
                                <th> 操作 </th>
                            </tr>
                        </thead>
                        <tbody>
                        <s:if test="termNoBeanList!=null && !termNoBeanList.isEmpty()">
                            <s:iterator value="termNoBeanList" var="tList">
                                <tr>
                                    <td> ${tList.termNo.fsn} </td>
                                    <td> ${tList.merchantName} </td>
                                    <td> ${tList.merchantNo} </td>
                                    <td>
                                        <s:iterator value="statusMap" var="tmp">
                                            <s:if test="#tmp.key==#tList.termNo.fstatus">${value}</s:if>
                                        </s:iterator>
                                    </td>
                                    <td>
                                    <s:if test="#tList.termNo.fstatus != 3">
                                            <a href="term_cancel.shtml?termNoId=${tList.termNo.fid }" onclick="return confirm('确定注销此终端序列号吗?');" class="bt02">注销</a>
                                            </s:if>
                                    </td>
                                </tr>
                            </s:iterator>
                                </s:if><s:else><tr>
                                    <td colspan="5" style="color: red;"> 没有数据,请导入数据 </td>
                                </tr></s:else>
                        </tbody>
                    </table>
                    <div class="page t-aligC">
                    当前是<strong>${page.currentPage}/${page.pageNum}</strong>页
                        <span><a href="term_showAll.shtml?termNo=${termNo}&fsn=${fsn}&status=${status }&currentPage=1">首页</a>
                        </span>
                        <span><a
                            href="term_showAll.shtml?termNo=${termNo}&fsn=${fsn}&status=${status }&currentPage=${page.prePage}">上一页</a>
                        </span>
                        <span><a
                            href="term_showAll.shtml?termNo=${termNo}&fsn=${fsn}&status=${status }&currentPage=${page.nextPage}">下一页</a>
                        </span>
                        <span><a
                            href="term_showAll.shtml?termNo=${termNo}&fsn=${fsn}&status=${status }&currentPage=${page.pageNum}">尾页</a> </span>
                    </div>
                </div>

                <!--列表end-->
            </div>
            <!--end right-->
        </div>
        <!--主要部分结束-->
        <!--页底开始-->
        <%@include file="/include/root_footer.jsp"%>
        <!--页底结束-->
    </body>
</html>


0 0
原创粉丝点击