2

I have a slider, and each slide has content-editable set to true. Meaning, each slide is basically a form. Upon creating a slide, I embed a data-id attribute into each of the slide's fields, so that I can grab the field values from any particular slide.

The problem is, When I grab the field values with a data-id attribute set to 1 it also grabs the field values from the slide with a data-id attribute set to 10.

Why is this happening?

Here is the code I use to grab any particular slide's values on an event trigger:

    var dealID = $(e.currentTarget).data("id");
    console.log("Deal ID: " + dealID);
    var dealTitleText = $('#deal-main-title[data-id*="' + dealID + '"]').text();
    var dealProvider = $('#deal-main-provider[data-id*="' + dealID + '"]').text();
    var dealDescription = $('#deal-main-description[data-id*="' + dealID + '"]').text();
    var dealPhoneNumber = $('#deal-main-phonenumber[data-id*="' + dealID + '"]').text();
    var dealConditions = $('#deal-main-conditions[data-id*="' + dealID + '"]').text();
4

1 回答 1

8

[data-id*="1"]查找data-id 包含 1的所有元素。如果你想要相等,只使用等号:

$('#deal-main-title[data-id="' + dealID + '"]')
于 2013-04-23T01:14:19.603 回答