亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

jquery實(shí)現(xiàn)動態(tài)創(chuàng)建form并提交的方法示例

 更新時間:2019年05月27日 11:18:35   作者:yihaomen  
這篇文章主要介紹了jquery實(shí)現(xiàn)動態(tài)創(chuàng)建form并提交的方法,結(jié)合實(shí)例形式分析了jQuery form表單創(chuàng)建與提交相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了jquery實(shí)現(xiàn)動態(tài)創(chuàng)建form并提交的方法。分享給大家供大家參考,具體如下:

有時候在寫web 應(yīng)用的時候,需要臨時動態(tài)構(gòu)造一個form 并提交,form 里面的參數(shù)以及action,以及是post請求還是get請求,甚至form 的樣式都是可以指定的,用原生的javascript  肯定可以做到,我用jquery做了一個測試。

我自己測試的是構(gòu)造一個分頁的post請求, 為了防止csrf 攻擊,加入了csrf 驗證,不需要的可以去掉.

function genSearchObj(url,page,pageSize,keyword){
  var params = {};
  params.url = url;
  params.page = page;
  params.pageSize = pageSize;
  params.cond = keyword;
  return params;
}
function mockFormSubmit(params){
  var form = $('<form />', {action : params.url, method:"post", style:"display:none;"}).appendTo('body');
  $.each(params, function(k, v) {
     if ( k != "url" ){
       form.append('<input type="hidden" name="' + k +'" value="' + v +'" />');
     }
  });
  form.append('<input type="hidden" name="csrfToken" value="' + $("#csrf_token").val() + '" />' );
  form.submit();
}

這樣就動態(tài)構(gòu)造了一個form ,并提交。

附:js動態(tài)創(chuàng)建Form表單并提交的方法

var dlform = document.createElement('form');
dlform.style = "display:none;";
dlform.method = 'post';
dlform.action = '../fileServlet';
dlform.target = 'callBackTarget';
var hdnFilePath = document.createElement('input');
hdnFilePath.type = 'hidden';
hdnFilePath.name = 'filePath';
hdnFilePath.value = filePath;
dlform.appendChild(hdnFilePath);
document.body.appendChild(dlform);
dlform.submit();
document.body.removeChild(dlform);

更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery form操作技巧匯總》、《jQuery操作json數(shù)據(jù)技巧匯總》、《jQuery常用插件及用法總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery表格(table)操作技巧匯總》及《jquery選擇器用法總結(jié)

希望本文所述對大家jQuery程序設(shè)計有所幫助。

相關(guān)文章

  • jQuery限制圖片大小的方法

    jQuery限制圖片大小的方法

    這篇文章主要介紹了jQuery限制圖片大小的方法,對比分析了常見的jQuery限制圖片操作方法及改進(jìn)方法,具有一定參考借鑒價值,需要的朋友可以參考下
    2016-05-05
  • jQuery的Ajax用戶認(rèn)證和注冊技術(shù)實(shí)例教程(附demo源碼)

    jQuery的Ajax用戶認(rèn)證和注冊技術(shù)實(shí)例教程(附demo源碼)

    這篇文章主要介紹了jQuery的Ajax用戶認(rèn)證和注冊技術(shù),結(jié)合完整實(shí)例較為詳細(xì)的分析講解了jQuery中ajax方法實(shí)現(xiàn)用戶驗證與注冊的相關(guān)技巧與注意事項,并附帶了demo源碼供讀者下載,需要的朋友可以參考下
    2015-12-12
  • 最新評論