Home  >  Article  >  Web Front-end  >  How to control a tag jump in jquery

How to control a tag jump in jquery

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

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

baidu
// 直接是触发click事件是无法跳转的
$('a#toMain').trigger('click') ;

Correct example

// 如果要用jquery触发进行跳转,那么a标签中【必须要有其它子标签】,然后触发该子类标签才能进行跳转

  

baidu

// 要有子标签
// 这里触发的是a标签中的p标签 $('a#toMain>p').trigger('click') ;

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

var myUrl = 'http://www.baidu.com';
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