jQuery를 사용하여 버튼 클릭으로 페이지에 동적으로 추가되는 Div가 있습니다.Div의 id를 함수의 인수로 전달하는 방법
RemoveArtist()
기능을 사용하여 cross-button.png 클릭으로 Div를 제거하고 싶습니다.
$("<div class=\"input-append\" id=\"artist"
+ artists.length - 1 + "\" ><label style=\"background-color:#e0ffff\">"
+ artistVal + "</label><img onclick=\"RemoveArtist()\" id=\"removeartist\""
+ " src=\"/Content/bootstrap/img/cross-button.png\" /></div>")
.appendTo(addDiv);
제거 아티스트 fucntion은 다음과 같아야합니다
var RemoveArtist = function (div,artistlength) {
$('div').remove();
artists.splice(artistlength, 1);
};
가 어떻게 또한 실제 RemoveArtist
함수 사업부와 사업부의 artists.length - 1
값이있는 artistlength
를 전달할 수 있습니다?
그래서 기본적으로 Div를 삭제하고 아티스트 배열에서 아티스트를 삭제하려고합니다.
그냥 조언 : 당신이 jQuery를 사용하는 경우, 기존의 이벤트가 등록 사용하지 마십시오. 그것을 위해 jQuery를 사용하십시오. 따라서 'onclick'속성은 없습니다. – MaxArt