如何创建条件以查看是否创建了具有特定值的href

时间:2016-01-21 12:43:59

标签: javascript jquery

所以我有这段代码<a href="#original" data-toggle="tab"><strong>text</strong></a> 当我点击某个按钮时,会创建一个href =&#34; #original,现在我的问题是如何创建一个条件来查看是否创建了这个特定的href?

$(document).ready(function() {
    if ($("[attribute$='#original'").length) {
        console.log('test');
    }
});

这是我到目前为止所做的。

2 个答案:

答案 0 :(得分:3)

$( document ).ready(function() {
    if ( $("a[href='#original']").length ) {
        console.log('test');
    }
});

使用属性href来找到它

答案 1 :(得分:0)

$( document ).ready(function() 
{
    if ($("[href$='#original'").length ) 
    {
        console.log($('a').attr('href'));
    }
});

http://www.w3schools.com/jquery/sel_attribute_end_value.asp