In jquery, the href attribute value in ie6 cannot be obtained. Solution:

Source: Internet
Author: User

To create an ajax paging function, you need to obtain the value of the href attribute.

Html file

The code is as follows: Copy code
<Div id = "ajaxpage">
<Span> 47/10 pages </span>
<A href = "? Page = 0 "onclick =" return false "> page 1 </a>
<A href = "? Page = 2 "onclick =" return false "> Previous page </a>
<A href = "? Page = 0 "onclick =" return false "> 1 </a>
<A href = "? Page = 1 "onclick =" return false "> 2 </a>
<A href = "? Page = 2 "onclick =" return false "> 3 </a>
<A href = "? Page = 3 "onclick =" return false "> 4 </a>
<A href = "? Page = 4 "onclick =" return false "> 5 </a>
<A href = "? Page = 5 "onclick =" return false "> 6 </a>
<A href = "? Page = 4 "onclick =" return false "> Next page </a>
<A href = "? Page = 9 "onclick =" return false "> Last page </a>
</Div>

It is sufficient to use the jQuery attr method in common traffic generators.
Var url = $ (this). attr ('href ');

However, what we get under IE6 is not the correct property value, but the URL with the domain name. This is not a jQuery bug, it is an ie problem, and will not happen in the high version.
Example: http://www.111cn.net? Page = 2

Special solutions are needed to solve this problem.

Solution

The code is as follows: Copy code

Var url = $ (this). attr ('href ');
Var base = window. location. href;
Var endIndex = url. lastIndexOf ("? ");
If (endIndex ){
Base = window. location. href. substring (0, endIndex );
}
Url = url. replace (base ,"");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.