在href中使用javascript导航到不同html页面的div部分 [英] Navigate to div section of a different html page using javascript in href

查看:79
本文介绍了在href中使用javascript导航到不同html页面的div部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < p>< p>< p>< ; a href =javascript:show_processor()>处理器< / a> 
< a href =javascript:show_ram()> RAM< / a>

但是,我想直接导航到system_details.html页面的 show_ram() 来自不同的html页面的功能(index.html)

解决方案

给链接和id < a href =javascript:show_ram()id =ram> RAM< / a> 。使用像 index.html#ram 这样的散列在URL末尾添加 id



然后使用 jQuery 来做这样的事情:



$ $ $ $ $ $ $ $ $ $ $'$''$'$'$'$'$'$($)$ .hash).click();
});

这会将散列后的URL的最后部分作为 id点击链接的,然后在指定的 id 链接上调用 click() c $ c>。


I am using javascript function to jump to a div section on the current html page(system_details.html):

<a href="javascript:show_processor()">Processor</a>
<a href="javascript:show_ram()">RAM</a>

However, I want to directly navigate to system_details.html page's show_ram() function from a different html page (index.html)

解决方案

Give the links and id <a href="javascript:show_ram()" id="ram">RAM</a>. Add this id at the end of the URL using a hash like so index.html#ram.

Then use jQuery to do something like this:

$(document).ready(function(){
  if(window.location.hash) $('#' + window.location.hash).click();
});

This will take the last part of the URL after the hash as the id of the link to be clicked on, and then call click() on the link with the specified id.

这篇关于在href中使用javascript导航到不同html页面的div部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆