<form id="myFormId" name="myForm" action="" method="post">
<input type="text" id="name" name="name" />
</form>
一: js操作
//需要注意的是form标签一定要有name属性,光有id没有name不起作用
document.myForm.action = "user.do";
document.myForm.attributes["action"].value = "XXXXXXXX";
document.all("myFormId").setAttribute("action", "欲赋的action的值");
document.MyForm.target="Doing";
document.MyForm.action="ask_tj.asp";
document.MyForm.method="POST"
document.MyForm.submit();
二 :Jquery操作
$("#myFormId").attr("action", "userinfo.shtml");
$("#myFormId").attr("target","_blank");
$("#myFormId").attr("method","POST");
$("#myFormId").attr("enctype","application/x-www-form-urlencoded");
$("#myFormId").attr("encoding","application/x-www-form-urlencoded");
$("#myFormId").submit();
注:
改变form的enctype属性时,如果只写$("#form").attr("enctype","application/x-www-form-urlencoded");
将不起作用,必须将以下两句结合才能生效:
$("#myFormId").attr("enctype","application/x-www-form-urlencoded");
$("#myFormId").attr("encoding","application/x-www-form-urlencoded");
三: jquery给form动态添加表单信息
var form = $("#myFormId");
// 创建Input
var my_input = $('<input type="text" name="my_name" />');
my_input.attr('value', my_val);
// 附加到Form
form.append(my_input);
// 提交表单
form.submit();