IE和FF2中可以:<form name="abcForm" method="get" id="abcForm">
<table id="abc" >
</table>
</form>
<script>
function createForm(){
var tbl = document.getElementById("abc");
var tr = tbl.insertRow(-1);
var td = tr.insertCell(-1);
td.innerHTML = " <input type='checkbox' value='true' name='tdname'/>Name"
var tr2 = tbl.insertRow(-1);
var td2 = tr2.insertCell(-1);
td2.innerHTML = " <select id=td2 name=tdvalue onchange='submitForm()'> <option value=1>1 </option> <option value=2>2 </option> </select>" }
function submitForm(){
document.abcForm.action = "xxxxxx";
document.abcForm.submit();
}
createForm();
</script>可以转到xxxxxx?tdname=true&tdvalue=2
<table id="abc" >
</table>
</form>
<script>
function createForm(){
var tbl = document.getElementById("abc");
var tr = tbl.insertRow(-1);
var td = tr.insertCell(-1);
td.innerHTML = " <input type='checkbox' value='true' name='tdname'/>Name"
var tr2 = tbl.insertRow(-1);
var td2 = tr2.insertCell(-1);
td2.innerHTML = " <select id=td2 name=tdvalue onchange='submitForm()'> <option value=1>1 </option> <option value=2>2 </option> </select>" }
function submitForm(){
document.abcForm.action = "xxxxxx";
document.abcForm.submit();
}
createForm();
</script>可以转到xxxxxx?tdname=true&tdvalue=2
这些值都是动态的哎。
提交前怎么会知道啊~~~~~
我想这个不是我要的效果
thanks anyway
不过我想知道一下这句话的意图是?“<select id=td2 name=tdvalue onchange='submitForm()'>”
select也表单中的一项,不是更改了select就要提交的
可能还有很多东西 都填完了
按一个按钮再提交
是否可以指点我的代码关键错在哪里,我好有针对性的解决。
非常感谢!
那只是个DEMO,在select change后触发你的submitForm,你可以自己随意处理,比如在点击某个提交按钮时触发,你的代码本身是没有什么问题的。
可是我的代码在ff下没有效果哎
我没看出来你改了哪里
除了post改成get
这个代码如果在ff下执行,再用ff的页面信息-表单查看的话
checkbox和select都不在abcForm里
我想可能就是这个原因导致提交失败
难道说你的可以?~~~~~
<table id="abc">
<tbody><tr><td> <input value="true" name="tdname" type="checkbox">Name</td></tr><tr><td> <select id="td2" name="tdvalue" onchange="submitForm()"> <option value="1">1 </option> <option value="2">2 </option> </select></td></tr></tbody></table>
</form>
<script>
function createForm(){
var tbl = document.getElementById("abc");
var tr = tbl.insertRow(-1);
var td = tr.insertCell(-1);
td.innerHTML = " <input type='checkbox' value='true' name='tdname'/>Name"
var tr2 = tbl.insertRow(-1);
var td2 = tr2.insertCell(-1);
td2.innerHTML = " <select id=td2 name=tdvalue onchange='submitForm()'> <option value=1>1 </option> <option value=2>2 </option> </select>" }
function submitForm(){
document.abcForm.action = "xxxxxx";
document.abcForm.submit();
}
createForm();
</script></body></html>
生成的东西应该都是在form中
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title></title>
<script>
function createForm(){
var tbl = document.getElementById("abc");
var tr = tbl.insertRow(-1);
var td = tr.insertCell(-1);
td.innerHTML = "<input type='checkbox' onclick='cbPjn()' value='true' name='tdname'/>Name"
var tr2 = tbl.insertRow(-1);
var td2 = tr2.insertCell(-1);
td2.innerHTML = "<select id=td2> <option value=1>1 </option> <option value=2>2 </option> </select>" }
function submitForm(){
alert(document.abcForm.tdname.value);
alert(document.abcForm.td2.value);
//document.abcForm.action = "xxxxxx";
document.abcForm.submit();
}
</script>
</head>
<body onload="createForm()">
<form name="abcForm" method="post" onsubmit="submitForm()">
<table id="abc" >
</table>
<input type="submit" />
</form></body>
</html>
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title></title>
<script>
function createForm(){
var tbl = document.getElementById("abc");
var tr = tbl.insertRow(-1);
var td = tr.insertCell(-1);
td.innerHTML = "<input type='checkbox' onclick='cbPjn()' value='true' name='tdname'/>Name"
var tr2 = tbl.insertRow(-1);
var td2 = tr2.insertCell(-1);
td2.innerHTML = "<select id=td2> <option value=1>1 </option> <option value=2>2 </option> </select>" }
function submitForm(){
alert(document.abcForm.tdname.value);
alert(document.abcForm.td2.value);
//document.abcForm.action = "xxxxxx";
document.abcForm.submit();
}
</script>
</head>
<body onload="createForm()">
<form name="abcForm" method="post" onsubmit="submitForm()">
<table id="abc" >
</table>
<input type="submit" />
</form></body>
</html>
原来是form要在<body>下,不能再有<table>节点
我能不能都给分啊。