我需要获取<p>
.T的ID像这样编码:
var p = $(this).closest('li').find('p[id^=name]').text();
它仅返回文本值,而不返回数字。
我的代码是这样的:
$.each(response.mname, function (i, mname) {
$('#feat').append(
'<li>' + '<a>' +
'<h4>' + '<p id=name' + i +'>' + mname.Name + '</p>' + '</h4>' +
'<input type="button" value="infobutton" background-color="green" id="button' + i +'" >' + '</input>' +
'</a>' + '</li>');
});
$("input[id^=button]").click(function () {
var p = $(this).closest('li').find('p[id^=name]').text();
alert(p);
});
试试这个
'<p id="name' + i +'">'
如果您想要ID也要更改
var p = $(this).closest('li').find('p[id^=name]').attr('id').replace(/name/, '');
它将仅从名称1,名称2等名称返回整数1,2。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句