2012-08-12 55 views
0

如何正确编辑下面的行以包含特定的类,而不是href属性?定义一个类而不是属性

var activeTab = $(this).find("a").attr("href"); 
+2

准确地说,“包含一个特定的类”是什么意思?请添加更多细节或理想情况下的示例。 – 2012-08-12 14:53:41

+0

你想要选择什么课程? – 2012-08-12 14:53:45

回答

1

尝试

var activeTab = $(this).find("a.className").attr("href"); 

如果使用

.attr("href"); 

它不会匹配href而是会返回匹配a标签

1

尝试的href;

var activeTab = $(this).find('.your_class').attr("href"); 

或者您可以尝试closest() like;

var activeTab = $(this).closest('tr').find('.your_class').attr("href"); 
//i took <tr> as a child in this example just for a demo. You may change it according to your HTML structure 

或者您可以尝试children like;

var activeTab = $(this).children('.your_class').attr("href"); 

希望这会有所帮助。

相关问题