这里点击删除按钮我需要获取图像按钮的当前ID。如何获取使用jquery动态创建的图像标记的id
var deleteButton = document.createElement("img");
deleteButton.setAttribute("style", "height:20px;width:20px;float:right;padding-right:5px");
deleteButton.setAttribute("class", "btnposition");
deleteButton.setAttribute("id", "deleteButton" + _SerialNumber);
var onclickMethod1 = "DeleteBillDetails('billDetailsWrap','wholeInsideId'," + _SerialNumber +")";
deleteButton.setAttribute("onclick", onclickMethod1);
deleteButton.src = "../../Images/Delete.png";
packingRow1.appendChild(deleteButton);
答案 0 :(得分:1)
您可以从控件中删除onclick方法,并使用以下方法编写逻辑。您可以轻松地以这种方式获取ID
$(document).on('click','.btnPosition',function(){
var id= $(this).prop('id');
// Write your logic here
})
OR
$('.btnPosition').click(function(){
var id = $(this).prop('id');
// Write your logic here
})