How to solve the & amp; (macro) symbol problem in src set by jquery attr

Source: Internet
Author: User

Problem description:

The html code is as follows:

<Iframe src = "http://www.jb51.net" id = "addOrUpdateIframe" style = "width: 870px; height: pixel PX;" border = "0" scrolling = "yes"> </iframe>

I used the attr method of jquery to set the src attribute of iframe.

$ ("# AddOrUpdateIframe"). attr ("src", "http://blog.jb51.net/search.aspx? Key = 400 "); // click the link to view the number of pages (the first page of data is displayed)

No problem. I got the desired result, but the following address drops all the parameters following the key (the parameters in the red font are not obtained)

$ ("# AddOrUpdateIframe"). attr ("src", "http://blog.jb51.net/search.aspx? Key = 400 & page = 2 "); // you can click the link to view the effect. Note the number of pages (the second page is displayed)


Depressed, I felt very strange. I used firebug to look at the modified value. I found the problem. jquery changed the above address:

Http://blog.jb51.net/search.aspx? Key = 400 & page = 2 // click the link to view the effect. Note the number of pages (the first page of data is displayed)

Depressed ................

I haven't found a solution for a long time. How can I change the address &? Not understand

Solution:

Accidentally

$ ("# AddOrUpdateIframe"). attr ("src", "http://blog.jb51.net/search.aspx? Key = 400 & page = 2 "); // you can click the link to view the effect. Note the number of pages (the first page of data is displayed)

Change

$ ("# AddOrUpdateIframe"). attr ("src", 'HTTP: // blog.jb51.net/search.aspx? Key = 400 & page = 2'); // you can click the link to view the effect. Note the number of pages (the second page is displayed)

Pay attention to the gray background and change the double quotation marks to single quotation marks. The problem is solved.

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.