php中 jquery如何获取js动态添加的文本框数组值,并插入mysql数据库?

php中 jquery如何获取js动态添加的文本框数组值,并插入mysql数据库?,第1张

建2个页面
1、testphp页面,代码如下:
<title></title>
<script src="jquery-142minjs" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
x=100000;
y=1;
$("#dosubmit")click(function(){
var rand=parseInt(Mathrandom() (x - y ));
var rand1=StringfromCharCode(Mathfloor( Mathrandom() 26) + "a"charCodeAt(0));
var col="<input name=info["+rand1+rand+"] type='text' class='text' value='"+rand+"' />";
$("input[id=submit]")before(col);
})
$("#submit")click(function(){
$("form input[class=text]")each(function(){
var val=$(this)val();
})
})
})
</script>
<meta ><table id="dd">
<tr><td>aa</td></tr>
</table>
<input type="button" value="add" onclick="add()" />
<input type="button" value="length" onclick="length()" />
<script type="text/javascript" src="jquery-152minjs"></script>
<script>
function add() {
    $("#dd")append("<tr><td>dd</td></tr>");
}
function length() {
    alert($("#dd tr")length);
}
</script>

直接用js里的getElementsByName就可以获取所以name值相同的元素。但获取出来的并不是数组,而是类数组的元素集合。所以还需要一步变换,下面是简单代码:

        <body>
<input type="text" name="111" />
<input type="text" name="111" />
<input type="text" name="111" />
<input type="text" name="111" />
<input type="text" name="111" />
<input type="text" name="111" />
<input type="text" name="111" />
<input type="text" name="111" />
</body>
<script>
    var oInp = documentgetElementsByName('111');
    var aInp = [];
    for(var i=0;i<oInplength;i++){
        aInppush(oInp[i]);
    }
</script>   //这样aInp这个数组里存储的就是所以元素name为111的数组。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/13383378.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-07-25
下一篇 2023-07-25

发表评论

登录后才能评论

评论列表(0条)

保存