茄子在线看片免费人成视频,午夜福利精品a在线观看,国产高清自产拍在线观看,久久综合久久狠狠综合

    <s id="ddbnn"></s>
  • <sub id="ddbnn"><ol id="ddbnn"></ol></sub>

  • <legend id="ddbnn"></legend><s id="ddbnn"></s>

    簡述JavaScript提交表單的方式 (Using JavaScript Submit Form)
    來源:易賢網(wǎng) 閱讀:1404 次 日期:2016-07-19 15:10:40
    溫馨提示:易賢網(wǎng)小編為您整理了“簡述JavaScript提交表單的方式 (Using JavaScript Submit Form)”,方便廣大網(wǎng)友查閱!

    最近做項(xiàng)目遇到用Javascript提交表單的問題, 之前也做過幾次, 但是不夠全面, 這次總結(jié)出了幾種用JavaScript提交表單的方式, 并且對(duì)此作出了比較, 選出了一種最適合此項(xiàng)目的方式。

    我目前正在為Sun Communication Suite做一個(gè)創(chuàng)建用戶的小型系統(tǒng),大家都知道我們可以通過表單,Ajax 和鏈接來訪問服務(wù)器, 最簡單的方法就是使用連接, 例如:<a href=UserServlet?event=SEARCH_MAILING_LIST¤tPage=1&keyword="+keyword+"&searchBy="+searchBy+"&cn="+request.getAttribute("cn")+">First Page</a>, 把所有需要的數(shù)據(jù)全部寫到超鏈接上, 如果你能夠觀察一下就會(huì)知道,在上邊的鏈接中只有currentPage是變化的, 其他參數(shù)event, keyword, searbyBy和cn是不變的, 那么我就想到如果我能夠把這些不變的參數(shù)封裝到一個(gè)表單中, 當(dāng)用戶點(diǎn)擊上面的超鏈接的時(shí)候我用JavaScript把這個(gè)表單提交, 那么我自然會(huì)訪問到服務(wù)器。

    表單:

    <form name="pagination" id="pagination" action="UserServlet" method="get">

    <input type="hidden" name="currentPage" value="1"/>

    <Input type="hidden" name="cn" value="<%=request.getAttribute("cn")%>"/>

    <input type="hidden" name="keyword" value="<%=request.getAttribute("keyword")%>"/>

    <input type="hidden" name="searchBy" value="<%=request.getAttribute("searchBy")%>"/>

    <input type="hidden" name="event" value="SEARCH_USER_FOR_MAILING_LIST">

    </form>

    在提交表單的過程中, 我只需要把參數(shù)currentPage傳給JavaScript就好了,所以我就把上面的連接改為下邊的形式:

    <a href=# onclick=document.pagination.currentPage.value="+pages[j]+";document.pagination.submit();><span style='color: red;'>["+pages[j]+"]</span></a>

    大家要注意一定要把document.pagination.currentPage.value="+pages[j]+";寫在document.pagination.submit();的前邊, 這樣在用戶提交表單之前, 參數(shù)currentPage就已經(jīng)被修改為我們需要的數(shù)值。 這樣我就完成了用連接來提交表單, 但是我有遇到了一個(gè)問題, 我需要試用上面的這段代碼在很多頁面, 如果我能統(tǒng)一的寫一段JavaScript的話,就會(huì)方面我以后對(duì)整個(gè)系統(tǒng)做維護(hù), 所以我?guī)讓懥艘粋€(gè)JavaScript的函數(shù)。

    function submitForm(id,currentPage){

    //var currentPage = document.pagination.currentPage.value;

    //alert(currentPage);

    //currentPage=100;

    //var currentPage = document.pagination.currentPage.value;

    //alert(currentPage);

    document.pagination.currentPage.value=currentPage;

    var form = document.getElementById(id);

    form.submit();

    }

    然后我在超連接的onclick事件上條用這個(gè)函數(shù):

    <a href=# onclick=submitForm('pagination',"+pages[j]+")>["+pages[j]+"]</a>, 大家可以看到整段代碼簡潔了不少。

    所以我總結(jié)了一下,用Javascript提交表單大概有兩種寫法(根據(jù)我目前的理解)

    1. document.formName.submit();

    2. var form = document.getElementById(id);

    form.submit();

    下次我想和大家分享一下用JNDI實(shí)現(xiàn)分頁。我把這次的代碼附在下邊, 大家可以參考一下。

    commons.js

    function submitForm(id,currentPage){

    //var currentPage = document.pagination.currentPage.value;

    //alert(currentPage);

    //currentPage=100;

    //var currentPage = document.pagination.currentPage.value;

    //alert(currentPage);

    document.pagination.currentPage.value=currentPage;

    var form = document.getElementById(id);

    form.submit();

    }

    mailingListMemberAdd.jsp

    <%@page contentType="text/html" pageEncoding="UTF-8"%>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

    "http://www.w3.org/TR/html4/loose.dtd">

    <%@ page import="java.util.LinkedList" %>

    <%@ page import="java.util.Iterator" %>

    <%@ page import="java.util.ArrayList" %>

    <%@ page import="java.util.List" %>

    <%@ page import="my.gov.rmp.webmail.domain.User" %>

    <%@ page import="my.gov.rmp.webmail.util.Pager" %>

    <html>

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <title>Add Member to Mailing List:<%=request.getAttribute("cn")%></title>

    <script type="text/javascript" src="../js/commons.js"></script>

    </head>

    <body>

    <jsp:include page="../inc/admin/headerMail.jsp"/>

    <div id="main"> 

    <div id="contents" >

    <h2>Add new members to mailing list: <span style="color:blue;"><%=request.getAttribute("cn")%></span></h2>

    <form name="addMailingListMember" id="addMailingListMember" action="UserServlet" method="post">

    <table cellspacing="5" cellpadding="5">

    <% 

    Pager pager =(Pager) request.getAttribute("pager");

    int currentPage =pager.getCurrentPage();

    int pageSize = pager.getPageSize();

    int i=(currentPage-1)*pageSize;

    LinkedList users = (LinkedList)request.getAttribute("users");

    if(!users.isEmpty()){

    %>

    <tr style="font-weight:bold"><td>No.      

    </td><td>UID:</td><td>gCode:</td><td>Givenname:</td><td>Surname:</td><td>Mail:</td><td>Description:</td></tr>

    <%

    for(Iterator iter = users.iterator();iter.hasNext();){

    User user = (User) iter.next();

    i++;

    // Attributes attrs = user.getAttrs();

    %>

    <tr><td><%=i%>.  <input type="checkbox" name="uid" value="<%=user.getUid()%>" /></td>

    <td width="15%"><%=user.getUid()%></td>

    <td><%=user.getGCode()%></td>

    <td><%=user.getGivenName()%></td>

    <td><%=user.getSn()%></td>

    <td width="30%"><%=user.getMail()%></td>

    <td><%if(user.getDescription()==null||user.getDescription().length()==0){%>Not Set<%} else %><%=user.getDescription()%></td>

    </tr> 

    <%

    }

    %>

    <input type="hidden" name="cn" value="<%=request.getParameter("cn")%>"/>

    <input type="hidden" name="event" value="ADD_MAILING_LIST_MEMBER" />

    <tr><td><button onclick="return selectAllCheckBoxs('uid');">Select All</button></td><td><button onclick="return deselectAllCheckBoxs('uid')">Deselect All</button></td><td></td><td><input type="submit" name="submit" value="Add to Mailing List"/></td></tr>

    </table>

    </form>

    <hr>

    <P STYLE="margin-top:-5px;"><strong>Pages:</strong>

    <form name="pagination" id="pagination" action="UserServlet" method="get">

    <input type="hidden" name="currentPage" value="1"/>

    <Input type="hidden" name="cn" value="<%=request.getAttribute("cn")%>"/>

    <input type="hidden" name="keyword" value="<%=request.getAttribute("keyword")%>"/>

    <input type="hidden" name="searchBy" value="<%=request.getAttribute("searchBy")%>"/>

    <input type="hidden" name="event" value="SEARCH_USER_FOR_MAILING_LIST">

    </form>

    <%

    int[] pages = pager.getPages();

    String keyword = request.getAttribute("keyword").toString();

    String searchBy = request.getAttribute("searchBy").toString();

    if(pager.isHasFirst()){

    out.println("<a href=UserServlet?event=SEARCH_USER_FOR_MAILING_LIST¤tPage=1&keyword="+keyword+"&searchBy="+searchBy+"&cn="+request.getAttribute("cn")+">First Page</a>  ");

    }

    if(pager.isHasPrevious()){

    out.println("<a href=# onclick=submitForm('pagination',"+(pager.getCurrentPage()-1)+")>Prev Page</a>  ");

    }

    for(int j=0;j<pages.length;j++){

    if(pager.getCurrentPage()==pages[j]){

    out.println("<a href=# onclick=document.pagination.currentPage.value="+pages[j]+";document.pagination.submit();><span style='color: red;'>["+pages[j]+"]</span></a>");

    }else {

    out.println("<a href=# onclick=submitForm('pagination',"+pages[j]+")>["+pages[j]+"]</a>");

    }

    }

    if(pager.isHasNext()){

    out.println("<a href=# onclick=submitForm('pagination',"+(pager.getCurrentPage()+1)+")>Next Page</a>  ");

    }

    if(pager.isHasLast()){

    out.println("<a href=# onclick=submitForm('pagination',"+pager.getTotalPage()+")>Last Page</a>  ");

    }

    %>

    </P>

    <%

    } else {

    //make the mailing list member availabe when user are trying to re-run the search 

    //request.setAttribute("members", members);

    %>

    <p>No results are matched your keyword or the user that you are looking for is already a member of this mailing list, please specify another keywork and <a href="<%=request.getContextPath()%>/admin/mailingListMemberSearch.jsp?cn=<%=request.getParameter("cn")%>">Search Again</a></p>

    <% 

    }

    %>

    </div>

    </div>

    </body>

    </html>

    更多信息請(qǐng)查看網(wǎng)絡(luò)編程
    易賢網(wǎng)手機(jī)網(wǎng)站地址:簡述JavaScript提交表單的方式 (Using JavaScript Submit Form)
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2026上岸·考公考編培訓(xùn)報(bào)班

    • 報(bào)班類型
    • 姓名
    • 手機(jī)號(hào)
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報(bào)警專用圖標(biāo)