0

我正在尝试向li通过 jQuery 添加到 DOM 的单击处理程序添加。我认为这就是你这样做的方式:

jQuery('.deleteUpload').on('click', '.deleteUpload', function() {
    var strDocId = jQuery(this).prop('id');
    //if (confirm('Are you sure you want to delete this resource') == true) {
        $.post('/study-clubs/meetings/delete-upload', {strDocId : strDocId},
            function(objData){
                console.log(objData);
            }
        );
        jQuery('li#' + strDocId).remove();
    //}

    return false;
});

这是我的标记:

<li class="pdf deleteLi" id="<?php echo $this->escape($this->objDocRow->id); ?>">
   <label><input type="radio" name="documents[1]" value="0" /> Pre-Meeting</label> &nbsp;
   <label><input type="radio" name="documents[1]" value="1" /> Post-Meeting</label> &nbsp;
   <label><input type="radio" name="documents[1]" value="2" checked /> Do Not Use</label> &nbsp;
   <a href="#" class="deleteUpload" id="2">Delete</a> &nbsp;
   <a href="/..."><?php echo substr($this->escape($this->objDocRow->doc_title), 0, -4); ?></a>
</li>

li您单击a带有deleteUpload. 我究竟做错了什么?当我点击它时,我被带到了页面的顶部。我也尝试过deleteLi而不是deleteUpload在 jQuery 中,但这也不起作用。

4

2 回答 2

2

尝试将第一行更改为:

jQuery('.deleteLi').on('click', '.deleteUpload', function() {
于 2013-05-09T21:23:12.660 回答
1

不需要第二个选择器。有了它,jquery 将查找具有 deleteUpload 类的 .deleteUpload 的子级。

jQuery('.deleteUpload').on('click', function() {
    var strDocId = jQuery(this).prop('id');
    //if (confirm('Are you sure you want to delete this resource') == true) {
        $.post('/study-clubs/meetings/delete-upload', {strDocId : strDocId},
            function(objData){
                console.log(objData);
            }
        );
        jQuery('li#' + strDocId).remove();
    //}

    return false;
});
于 2013-05-09T21:24:12.770 回答