获取javascript中的URL链接名称
Get URL link name in javascript?
嗨,我正试图通过使用javascript让我的选项卡正常工作,但在更改包含内容的div时遇到了一些问题。
这些是我的标签,还有更多,但我会显示2个,例如
<li id="sub1" class="moduleTabs"><a href="#">Practice</a>
<ul class="collapse">
<li class="unselected"><a href="#pro1" id="t1">Principle</a></li>
<li class="unselected"><a href="#pro2" id="t2">Basics</a></li>
</ul>
</li>
这是我的div,包含内容
<div id="pro1" class="information">
<h2>Principles</h2>
<p></p>
</div>
<div id="pro2" class="information">
<h2>Basics</h2>
<p></p>
</div>
这是我的javascript代码
$('#t1, #t2, #t3, #t4, #t5, #t6, #t7, #t8, #t9, #t10, #t11, #t12, #t13, #t14').parent('li').click(function () {
$(this).addClass('clicked');
$(this).siblings().removeClass('clicked');
//this part is to remove the content in homepage
$('#content').hide();
//i'm trying to get the url name #pro1 if link #t1 is click so that the div will fade in
$(this).find('a').attr('href').fadeIn();
$(this).siblings().find('a').attr('href').hide();
})/
我现在面临的问题是$(this).find('a').attr('href').fadeIn()
不起作用。我无法从所选的选项卡中获取url链接(#pro1)
。
问题是$(this).find('a').attr('href')
会返回一个类似"#pro1"、"#pro2"的字符串。。。而不是直接的jQuery对象。您必须将这个字符串提供给jQuery函数才能获得相应的元素。
更改此项:
$(this).find('a').attr('href').fadeIn();
至
$($(this).find('a').attr('href')).fadeIn();
相关文章:
- 每5次访问后更改链接URL
- 将链接 URL 变量传递给 javascript
- 更改链接 URL 中的路径名,同时保持查询字符串不变
- ASP.Net JavaScript 表的 MVC 操作链接/URL 操作 - datatable.net
- 如何获取文本中的所有链接 (URL)
- 在单击链接时运行数据库查询,但仍加载链接URL
- 保存超链接URL's来自所选文本
- 如何获得实际的硬链接URL
- 如果我在前端用javascript更改链接URL,可以在谷歌上抓取我的网站
- javascript自动链接url,但避免递归
- 动态链接URL包含声音管理器2要播放的wav文件的位置
- JSON文件中的超链接URL值
- 是否有一种方法来改变所有的网页链接url根据浏览器的url
- 获取HTML中输入字段的值,并在链接url中使用它
- Facebook的Like按钮和获取用户UID在链接URL
- 如何在javascript中获得所有超链接url和创建onclick
- 用javascript和链接url代替
- 链接URL到SSRS字段,报表服务器上没有数据
- 更新文本链接URL在d3
- 自动链接url在CKEditor