DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> JavaScript綜合知識 >> js創建表單元素並使用submit進行提交
js創建表單元素並使用submit進行提交
編輯:JavaScript綜合知識     

 js 創建form、input元素,並設置form的action及method,最後使用submit進行提交

01 <script src="Scripts/jquery-1.7.1.js"></script>  02   <script type="text/javascript">  03     function SubmitFormToSF() {  04       var sfForm = document.createElement("form");  05       document.body.appendChild(sfForm);  06       var mfInputs = "text1,checkbox1,Select1,Hidden1";  07       var sfInputs = "text1_c,checkbox1_c,Select1_c,Hidden1_c";  08       var mFInputsArray = mfInputs.split(",");  09       var sFInputsArray = sfInputs.split(",");  10       for (i = 0; i < mFInputsArray.length; i++) {  11         createInput(sfForm, "text", sFInputsArray[i], GetInputValue(document.getElementById(mFInputsArray[i])))  12       }  13       //創建聯系時間  14     15       //創建隱藏域  16     17       sfForm.method = "post";  18       sfForm.action = "c.aspx";  19       sfForm.submit();  20     }  21     function createInput(sfForm,type,name,value)  22     {  23       var tmpInput = document.createElement("input");  24       tmpInput.type = type;  25       tmpInput.name = name;  26       tmpInput.value = value;  27       sfForm.appendChild(tmpInput);  28     }  29     function GetInputValue(ipt)  30     {  31       switch (ipt.type)  32       {  33         case "text":  34           return ipt.value;  35           break;  36         case "hidden":  37           return ipt.value;  38           break;  39         case "checkbox":  40           return ipt.checked;  41           break;  42         case "select-one":  43           return ipt.value;  44           break;  45       }  46     }  47     function getContratTime() {  48       var anytime = $("#anytime");  49       var afternoon = $("#afternoon");  50       var morning = $("#morning");  51       var evening = $("#evening");  52       if (anytime.checked) {  53         return "morning,afternoon,evening";  54       } else {  55         if (morning.checked)  56         {  57           return morning.val();  58         } else if (afternoon.checked)  59         {  60           return afternoon.val();  61         } else if (evening.checked)  62         {  63           return evening.val();  64         }  65         return "";  66       }  67     }  68   </script>
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved