Home >Web Front-end >Front-end Q&A >How to control a tag jump in jquery

How to control a tag jump in jquery

藏色散人
藏色散人Original
2021-11-15 10:32:072375browse

The jquery method to control a tag jump: 1. Create an HTML sample file; 2. Add other sub-tags to the a tag; 3. Trigger the sub-category tag to jump.

How to control a tag jump in jquery

The operating environment of this article: windows7 system, jquery3.2.1 version, DELL G3 computer

jquery How to control a tag jump?

Use jquery to trigger a tag jump

Error example

<a href="http://www.baidu.com" target="_blank">baidu</a>
// 直接是触发click事件是无法跳转的
$(&#39;a#toMain&#39;).trigger(&#39;click&#39;) ;

Correct example

// 如果要用jquery触发进行跳转,那么a标签中【必须要有其它子标签】,然后触发该子类标签才能进行跳转
<a href="http://www.baidu.com" target="_blank">
  <p>baidu</p> // 要有子标签
</a>
// 这里触发的是a标签中的p标签
$(&#39;a#toMain>p&#39;).trigger(&#39;click&#39;) ;

JavaScript encodes the url URL, using encodeURIComponent That’s it

var myUrl = &#39;http://www.baidu.com&#39;;
var myOtherUrl =
  "http://www.jb51.net/index.html?url="+encodeURIComponent(myUrl);

Recommended learning: "jquery video tutorial"

The above is the detailed content of How to control a tag jump in jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn