我試圖在按下按鈕後將複選框添加到項目列表(鏈接)。
的想法是,我得到的鏈接,如清單:
- Google.com。
- Bing.com
- Cnn.com
等,我在頁面底部有按鈕,一旦按鈕被點擊我要添加複選框各個環節,但每箱ID應是它所連接的鏈接的序列號。
$("#links_remove").click(function(event) {
$('.links').after('<div><label> Check box to remove link: <input type="checkbox" class=" removebox" id="'+$(this).attr("id").split("_")[1]+'"></div>');
});
這是HTML
<a class="links" id="link_27" href="google.com">google.com</a>
但當然$(本)選擇獲得按鈕(「links_remove」)的當前連接的屬性,而不是。
謝謝!
當然'this'指的是按鈕,因爲這是分派事件的元素。 –