How can I get the data attribute from a php variable?

后端 未结 2 2033
猫巷女王i
猫巷女王i 2021-01-16 00:29

I have a form that can delete records from a MySql database using ajax and jQuery. I\'m trying to get the jQuery to only select the relevant record passed to it and not just

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-16 01:06

    I would recommend you to use data-* prefixed attributes to persists your data.

    HTML

     

    Then you can fetch it using .data(key)

    Return the value at the named data store for the first element in the jQuery collection, as set by data(name, value) or by an HTML5 data-* attribute

    Script

     //Delete Review
    $(document).ready(function(){
        //Need to get $id here.
        $(".deleteReview").click(function (e) {
            e.preventDefault();
            var username = $(this).data("username");
            var film_id = $(this).data('filmid');
            var id = $(this).data('id');
    
            ......
            return false;
        });
    });
    

提交回复
热议问题