js 創(chuàng)建form、input元素,并設(shè)置form的action及method,最后使用submit進(jìn)行提交
view sourceprint?
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 //創(chuàng)建聯(lián)系時(shí)間
14
15 //創(chuàng)建隱藏域
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>
更多信息請(qǐng)查看IT技術(shù)專欄