概述
<
script language
=
"
javascript
"
type
=
"
text/javascript
"
>
<!--
//
function that creates the form, adds some elements
//
and then submits it
function
select(id)
{
var
t
=
document.getElementById(
"
t
"
+
id);
var
d
=
document.getElementById(
"
d
"
+
id);
var
submitForm
=
getNewSubmitForm();
createNewFormElement(submitForm,
"
name
"
, t.innerHTML);
createNewFormElement(submitForm,
"
remark
"
, d.innerHTML);
submitForm.action
=
"
quote.aspx
"
;
submitForm.submit();
}
//
helper function to create the form
function
getNewSubmitForm()
{
var
submitForm
=
document.createElement(
"
FORM
"
);
document.body.appendChild(submitForm);
submitForm.method
=
"
POST
"
;
return
submitForm;
}
//
helper function to add elements to the form
function
createNewFormElement(inputForm, elementName, elementValue)
{
var
newElement
=
document.createElement(
"
input
"
);
newElement.setAttribute(
"
name
"
,elementName);
newElement.setAttribute(
"
type
"
,
"
hidden
"
);
newElement.setAttribute(
"
value
"
,elementValue);
inputForm.appendChild(newElement);
return
newElement;
}
//
-->
<
/
script>
注意document.createElement("FORM")来创建节点,在IE和Firefox下都可以
IE有3种方式都可以创建一个元素:
1 document.createElement("<input type=text>")
2 document.createElement("<input>")
3 document.createElement("input")
Firefox只支持一种方式:
document.createElement("input");document.setAttribute(name,value);
--------------
注: 在一个节点下增加子节点 IE也比Firefox下的方式要多.
IE:
1 node.insertBefore(Element)
2 node.insertAfter(Element)
3 node.appendChild(Element)
而Firefox仅支持 node.appendChild.
最后
以上就是兴奋鸭子为你收集整理的Javascript动态创建FORM提交的全部内容,希望文章能够帮你解决Javascript动态创建FORM提交所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复