如何从我的表单中获取查询参数值

时间:2018-02-01 22:32:45

标签: javascript jquery asp.net

我在创建表单中有以下标记: -

<form method="post" action="./NewForm.aspx?Source=http%3a%2f%2fwww.******.intra%2fOrderManagement%2fLists%2fOrderManagement%2fAllItems.aspx&amp;
ContentTypeId=0x0103006FFC142316C0B148896E3C32099B654E0100C4125A72ABD48B46AEB7AB17A2E53735&amp;RootFolder=%2fOrderManagement%2fLists%2fOrderManagement" onsubmit="javascript:return WebForm_OnSubmit();" id="aspnetForm" enctype="multipart/form-data">

现在我不确定如何获取ContentTypeId属性中action参数的值,以获取ID = aspnetForm的表单?

1 个答案:

答案 0 :(得分:0)

长话短说:

console.log(
  unescape($('#aspnetForm').attr('action'))
  .split('?').pop().split('&')
  .reduce(function(o, e){
    p = e.split('=');
    o[p[0]] = p[1];
    return o;
   }, {})
  .ContentTypeId
)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form method="post" action="./NewForm.aspx?Source=http%3a%2f%2fwww.******.intra%2fOrderManagement%2fLists%2fOrderManagement%2fAllItems.aspx&amp;ContentTypeId=0x0103006FFC142316C0B148896E3C32099B654E0100C4125A72ABD48B46AEB7AB17A2E53735&amp;RootFolder=%2fOrderManagement%2fLists%2fOrderManagement" onsubmit="javascript:return WebForm_OnSubmit();" id="aspnetForm" enctype="multipart/form-data">