html代码如下:<input type="text" id="txt1" >
<input type="text" id="txt2" >
<input type="text" id="txt3" >
<input type="text" id="txt4" >
<input type="text" id="txt5" >
<input type="text" id="txt6" ><!-- 隐藏域放所有值!-->
<input type="hidden" id="allinfo" >
且text还可以动态添加!
问题是如何获得所有text值然后放到 allinfo 好传到后台中!
谢谢请大家帮忙!
<input type="text" id="txt2" >
<input type="text" id="txt3" >
<input type="text" id="txt4" >
<input type="text" id="txt5" >
<input type="text" id="txt6" ><!-- 隐藏域放所有值!-->
<input type="hidden" id="allinfo" >
且text还可以动态添加!
问题是如何获得所有text值然后放到 allinfo 好传到后台中!
谢谢请大家帮忙!
解决方案 »
- event.srcElement.type 火狐的问题???
- 求个完整的dtree示例,必须是动态的!
- js 表格排序并编辑
- 如何使用JavaScript的正则表达式获取处于指定字符串开始以及指定字符串结尾的中间内容
- 请问window.open打开窗口位置问题,能不能在屏幕中居中显示,感谢
- 求个简单正则
- 虚心请教:访问我的网址,如果他还没有设置为主页,就弹出框框让他选择,是要设置还是不设置?这个代码怎么写呀?
- 如果何使两个Table的宽始终保持一样?
- wsj(骆驼) 进来了!多谢你的帮忙,大家也可以来转转 :)
- .js文件能否读取.js?参数
- javascript调试
- 要 "判断" 一个div到底是显示的还是隐藏的该怎么写
var content = "";
while(document.getElementById("txt" + i)) {
content += document.getElementById("txt" + i);
}//然后赋值、传值
<script>function doit(){
var f = document.forms[0];
var s = "";
for(var i=0;i<f.elements.length;i++){
if(f.elements[i].type != "text") continue;
if(f.elements[i].id.substr(0,3) != "txt") continue;
if(f.elements[i].value=="") continue;
s += f.elements[i].value + ",";
}
if(s!="") s =s.substr(0,s.length-1);
alert(s);
f.allinfo.value = s;
}
</script>
<form>
<input type="text" id="txt1" >
<input type="text" id="txt2" >
<input type="text" id="txt3" >
<input type="text" id="txt4" >
<input type="text" id="txt5" >
<input type="text" id="txt6" >
<input type="button" value="click" onclick="doit()">
<!-- 隐藏域放所有值!-->
<input type="hidden" id="allinfo" >
</form>
设置相同的name属性即可获取到各个文本框的内容
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title></title>
</head>
<script type="text/javascript" src="wsn_global_test.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var i=0;
$("#addBtn").click(function() {
i++;
$(this).after("<br /><input type='text' id='txt" + i + "' /><br />");
});
$("#showBtn").click(function() {
if($("input[id^='txt']").length > 0) {
var html = "";
$("input[id^='txt']").each(function() {
if($(this).val()) {
html += $(this).val() + ";";
}
});
$("#allinfo").val(html);
}
});
});
</script>
<body>
<a id="addBtn" href="javascript:void(0);">add it</a>
<input type="hidden" id="allinfo" />
<br />
<input type="button" value="show all value" id="showBtn" />
</body>
</html>
如果我上面还有一个需要单独提交的控件呢?
比如:<form>
<!-- 单独的-->
<input type="text" id="others" />
<!-- 单独的-->
<input type="text" id="txt1" >
<input type="text" id="txt2" >
<input type="text" id="txt3" >
<input type="text" id="txt4" >
<input type="text" id="txt5" >
<input type="text" id="txt6" >
<input type="button" value="click" onclick="doit()">
<!-- 隐藏域放所有值!-->
<input type="hidden" id="allinfo" >
<body>
<input type="text" id="txt1" value="111" />
<input type="text" id="txt2" value="222" />
<input type="text" id="txt3" value="333" />
<input type="text" id="txt4" >
<input type="text" id="txt5" >
<input type="text" id="txt6" >
<!-- 隐藏域放所有值!-->
<input type="hidden" id="allinfo" >
</body>
<script>
getAllInfo();
function getAllInfo(){
var allObj = document.getElementsByTagName("input");
for(var i=0;i<allObj.length;i++){
if(allObj[i].type == "text"){
if(allObj[i].value != null && allObj[i].value != ""){
document.getElementById("allinfo").value += allObj[i].value;
document.getElementById("allinfo").value += ",";
} }
}
alert(document.getElementById("allinfo").value);
}
</script>
</html>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>无标题页</title>
<script type="text/javascript">
function ShowInfo()
{
var Text=document.getElementsByTagName("input");
var Array="";
for(var i=0;i<Text.length;i++)
{
if(Text[i].type=="text")
{
Array+=",";
Array+=Text[i].value;
}
}
Array=Array.substring(1,Array.length-2);
document.getElementById('Hidden1').value=Array;
alert(document.getElementById('Hidden1').value);
}
</script>
</head>
<body>
<input type="text" id="txt1" ><br />
<input type="text" id="txt2" ><br />
<input type="text" id="txt3" ><br />
<input type="text" id="txt4" ><br />
<input type="text" id="txt5" ><br />
<input type="text" id="txt6" ><br />
<input id="Hidden1" type="hidden" />
<input id="Button1" type="button" value="提交" onclick="ShowInfo()" />
</body>
</html>
<script>
function getvalue(){
var a=[];
var o=document.getElementById("czp").getElementsByTagName("INPUT"); for(var i=0;i<o.length;i++){
a.push(o[i].value);
}
document.getElementById("czp").value=a.join(',')
//alert(document.getElementById("czp").value)
}
</script>
<!-- 单独的-->
<input type="text" id="others" /><div id=czp>
<input type="text" id="txt1" />
<input type="text" id="txt2" />
<input type="text" id="txt3" />
<input type="text" id="txt4" />
<input type="text" id="txt5" />
<input type="text" id="txt6" />
</div>
<br>
<input type="button" value="test" onclick="getvalue()"/><!-- 隐藏域放所有值!-->
<input type="hidden" id="allinfo" >
var o,t='';
for(var i=0;o=document.getElementById('txt'+i);i++){
t+=o.value;
}
document.getElementById('allinfo').value=t;
[/code]
6楼用jQuery可以将结构和行为更好地分离
function(i,v){
$("hidden").val(v.val());
}
)简单明了的JQ
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script language="JavaScript">
window.onload = function(){
var $ = function(id){
return document.getElementById(id);
};
var oInputs = document.getElementsByTagName('input');
var Result = "";
$('click').onclick = function(){
for (var i = 0; i < oInputs.length; i++) {
(function(obj){
if (obj.type == 'text' && obj.value != "" ) {
Result += obj.value!=""?obj.value:"";
Result += "|";
}
})(oInputs[i])
}
$('allinfo').value = Result;
alert($('allinfo').value);
};
};
</script>
</head>
<body>
<form>
<!-- 单独的-->
<input type="text" id="others" />
<!-- 单独的-->
<input type="text" id="txt1" >
<input type="text" id="txt2" >
<input type="text" id="txt3" >
<input type="text" id="txt4" >
<input type="text" id="txt5" >
<input type="text" id="txt6" >
<input type="button" value="click" id="click">
<!-- 隐藏域放所有值!-->
<input type="hidden" id="allinfo" >
</form>
</body>
</html>楼主看看~·