斌奋世界的gravatar头像
斌奋世界 2015-04-30 14:28:08

如何通过jquery获取js动态append到html页面的dom属性?

jsp中
 

<tr>
<th align="left" width="20%" style="width: 170px; ">分享文案编辑:</th>
</tr>
<tr>
<td class="form_table_content" ><input name="wshopshare"
id="wshopshare_1" type="text" style="width: 440px; ">
</td>
<td><input type="button" onclick="component.addshare();" id="addshare" value="添加">
</td>
</tr>

点击一次添加按钮页面多一个文本框
————————————————————————————————————————
JS中

$("#content1")
.append(
'<table id="1_'//id=1_type
+ type
+ '"><tr><td>分享语句'
+ type
+ '</td></tr><tr>'
+ '<td><div id="wshopshare"></div></td>'
+ '<td><input name="wshopshare" id="wshopshare" type="text" style="width: 440px; "></td>'
+ '<td></td>'
+ '<td><button type="button" id="del1" onclick="component.deleteAll(\'1\');">删除</button></td>'
+ '</tr></table>');

每添加按钮点一次,就添加一个文本框在页面上,

现在怎么设置动态的id="wshopshare_变量",id="wshopshare_1"id="wshopshare_2".。。。。。。。。。。。。

问题来了

怎么在JS中的JQUERY获得添加的文本框的ID,id="wshopshare_1".................多个


最代码官方编辑于2015-4-30 15:20:21
所有回答列表(2)
最代码官方的gravatar头像
最代码官方  LV167 2015年4月30日

代码如下:

<html>
<head>
<script src="http://static.zuidaima.com/resource/js/jquery.min.js"></script>
</head>
<body>
	<table id="table">
		<tr><td class="row">row1</td></tr>
		<tr><td class="row">row2</td></tr>
	</table>
	
	<button id="add">添加</button>
	<button id="get">获取</button>
</body>
<script>
	$(function() {
		$("#add").click(function() {
			var len=$(".row").length;
			len++;
			$("#table").append("<tr><td class='row'>row"+(len)+"</td></tr>");
		});
		$("#get").click(function() {
			
			for(var i=0;i<$(".row").length;i++){
				alert($(".row")[i].innerHTML);
			}
		});
	});
</script>

</html>

看看是否是需要这样的效果。

点击添加按钮后,自动增加table的tr td,点击获取后可以得到所有class=row的td。

如何通过jquery获取js动态append到html页面的dom属性?

斌奋世界的gravatar头像
斌奋世界  LV4 2015年5月13日

灰常感谢,特别感谢

顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友