通过它的属性和值找到一个html控件

时间:2016-03-02 09:03:24

标签: javascript jquery

我希望通过其属性找到<a>标记,通过javascript找到属性值...但它不起作用...

<a class="btn-u btn-u-split-red tooltips CancelOredr" data-guid="1351e01d-8e89-4adc-b3f2-10c0c8ccaa5b" href="/User/UserProfile/Index/1351e01d-8e89-4adc-b3f2-10c0c8ccaa5b" title="" data-placement="bottom" "></a>

<script>
    $(document).on('click', '.CancelOredr', function (e) {
        var OrderID = "1351e01d-8e89-4adc-b3f2-10c0c8ccaa5b";
        var trEl = $('[data_guid=' + OrderID + ']');
        trEl.css("background", "#F5F5AF");
        trEl.delay(1000).fadeOut(1000);
    });
</script>

1 个答案:

答案 0 :(得分:1)

你的JS中有一个下划线,它是你html中的连字符:

var trEl = $('[data_guid='+OrderID +']');

应该是:

var trEl = $('[data-guid='+OrderID +']');