jquery为data()返回undefined

时间:2014-08-19 19:29:30

标签: javascript jquery return undefined

我尝试了很多东西,仍然无法让它运行

<span data-comment-id="123456" class="delete_co">Delete button</span>
<div class="delete_confirm" style="display: none;">
    wanna delete?
    <form action="" method="post">
        <input type="button" value="cancel" class="delete_cc">
        <input type="submit" name="comment_delete" value="delete">
    </form>
</div>

<script>
$('.delete_co').click(function(){
    alert('' + $('.delete_co').data['comment-id']);
    $('.delete_confirm').css('display', 'block');
});
$('.delete_cc').click(function(){
    $('.delete_confirm').css('display', 'none');
});
</script>

http://jsfiddle.net/urK5L/10/

1 个答案:

答案 0 :(得分:1)

alert('' + $('.delete_co').data('comment-id'));

不是alert('' + $('.delete_co').data['comment-id']);

问题是[]