jquery on()获取clone出来的input里面的值

茫茫代码中的一粒渣渣 2018-05-24 03:14:28
我是一个代码新人第一次到CSDN来提问题,我现在动态克隆出来了一些input 然后我需要将这些动态clone出来的input里面的值取出来 发送给后台提交数据库
//被邀请人动态添加
function addPeople(){
var origin = $('[people]:last'),
index = Number(origin.attr('people')) + 1,
clone = origin.clone();
clone.attr('people', index);
clone.children(':first').text(index);
clone.find('input').val('');
origin.after(clone);

页面是这样的
<tr people="1">
<td class="Hui-text-center thead-bg layui-bg-orange">1</td>
<td class="Hui-text-center thead-bg">
<input type="text" class="input-text radius" placeholder="外文姓" item="engName"/>
</td>
<td class="Hui-text-center thead-bg">
<input type="text" class="input-text radius" placeholder="外文名" item="name"/>
</td>
<td class="Hui-text-center thead-bg">
<input type="text" class="input-text radius" placeholder="护照号码" item="passportNumber"/>
</td>
<td class="Hui-text-center thead-bg">
<input type="text" class="input-text radius" placeholder="性别" item="sex"/>
</td>
<td class="Hui-text-center thead-bg">
<select class="select input-text radius" size="1" id="county" item="nationality">
</select>
</td>
<td class="Hui-text-center thead-bg">
<input type="text" class="input-text radius layuidate" placeholder="出生年月日" item="birthDate"/>
</td>
</tr>
求个大神帮帮忙
...全文
1274 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_41760494 2021-02-26
  • 打赏
  • 举报
回复
引用 4 楼 茫茫代码中的一粒渣渣的回复:
谢谢各位大佬,我的问题已经解决了。
怎么解决的,求教
weixin_41760494 2021-01-14
  • 打赏
  • 举报
回复
怎么解决的?为什么我克隆出来没有字段?
ツ南栀 2020-10-16
  • 打赏
  • 举报
回复
求教怎么解决的。
  • 打赏
  • 举报
回复
谢谢各位大佬,我的问题已经解决了。
75闪光雷 2018-05-25
  • 打赏
  • 举报
回复
不知道 是不是你想要的,下次提问 把代码都贴出来,别贴一半,帮你的人还得自己写另一把 没时间的一般都不会搭理你了,只是建议,仅供参考。

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <script src="http://code.jquery.com/jquery-latest.js"></script>
<meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <title>Document</title>
 </head>
 <body>
<tr people="1">
<td class="Hui-text-center thead-bg layui-bg-orange">1</td>
<td class="Hui-text-center thead-bg">
<input id="firstname" type="text" class="input-text radius" placeholder="外文姓"   item="engName"/> 
</td>
<td class="Hui-text-center thead-bg">
<input id="secondname" type="text" class="input-text radius" placeholder="外文名"    item="name"/> 
</td>
<td class="Hui-text-center thead-bg">
<input id="passportNumber" type="text" class="input-text radius" placeholder="护照号码" item="passportNumber"/> 
</td>
<td class="Hui-text-center thead-bg">
<input  type="text" class="input-text radius" placeholder="性别"       item="sex"/> 
</td>
<td class="Hui-text-center thead-bg">
<select id="sex" class="select input-text radius" size="1" id="county"  item="nationality">
	<option value ="volvo">男</option>
	<option value ="volvo">女</option>
</select>
</td>
<td class="Hui-text-center thead-bg">
<input id="borth" type="text" class="input-text radius layuidate" placeholder="出生年月日" item="birthDate"/> 
</td>
</tr>	
<button onclick="senddata()">提交</button>
<script type="text/javascript">
 
function senddata(){
	var data={};
	data.firstname=$("#firstname").val();
	data.secondname=$("#secondname").val();
	data.passportNumber=$("#passportNumber").val();
	data.sex=$("#sex").val();
	data.borth=$("#borth").val();
	alert(JSON.stringify(data));
}
</script>
 </body>
 </html>
Hello World, 2018-05-25
  • 打赏
  • 举报
回复
你把内容放在form里面,提交就好了,有什么问题?
zgycsmb 2018-05-25
  • 打赏
  • 举报
回复
用clone 方法要方便些 克隆所有的 <p> 元素,并插入到 <body> 元素的结尾: $("button").click(function(){ $("p").clone().appendTo("body"); });

87,990

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧