Home >Web Front-end >JS Tutorial >Solution to the problem of jquery attr setting src containing & (macro) symbol_jquery

Solution to the problem of jquery attr setting src containing & (macro) symbol_jquery

WBOY
WBOYOriginal
2016-05-16 18:04:291088browse

Problem description:

The html code is as follows:



I use jquery's attr method to set the src attribute of the iframe

$ ("#addOrUpdateIframe").attr("src", "http://blog.jb51.net/search.aspx?key=400");//You can click the link to view the effect. Note the number of pages (display the first page of data) )

No problem, I got the results I wanted, but the following address lost all the parameters after the key (the parameters in red font were not retrieved)

$("# addOrUpdateIframe").attr("src", "http://blog.jb51.net/search.aspx?key=400&page=2");//You can click the link to view the effect. Pay attention to the number of pages (display the second page of data)


I was depressed and felt very strange, so I used firebug to check the modified value. The problem was found. jquery changed the above address into:

http:// blog.jb51.net/search.aspx?key=400&page=2//You can click the link to view the effect. Pay attention to the page number (display the first page of data)

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

I have been looking for it for a long time but I still can’t find it. If this problem is solved, why did he change the & in the address to &? I’m a bit confused about

Problem solution:

accidentally added

$("#addOrUpdateIframe").attr("src", "http://blog .jb51.net/search.aspx?key=400&page=2");//You can click the link to view the effect. Pay attention to the page number (display the first page of data)

is changed to

$( "#addOrUpdateIframe").attr("src", 'http://blog.jb51.net/search.aspx?key=400&page=2');//You can click the link to view the effect. Note the page number (display the second page Data)

Pay attention to the gray background, change the double quotes to single quotes, and the problem is solved.

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