所以我正在为一个我正在研究的网站开发一些jQuery,出于某种原因,当我在双引号Firefox中放入单引号时,在它的永恒荣耀中,将它们更改为双引号,从而破坏了我的代码
我甚至尝试将它放在外部javascript文件中,即使我现在只是原型设计。不好。不会加载文件!
$("#clips").after("<ul id='slideshow-nav'><li><a id='gallery-next' href='#' title='View the next piece'>Next</a></li><li><a id='gallery-prev' href='#' title='View the previous piece'>Prev</a></li></ul>");
我做错了吗?
答案 0 :(得分:1)
您是否尝试过切换单引号和双引号?
$("#clips").after('<ul id="slideshow-nav"><li><a id="gallery-next" href="#" title="View the next piece">Next</a></li><li><a id="gallery-prev" href="#" title="View the previous piece">Prev</a></li></ul>');
答案 1 :(得分:1)
您是否考虑过: -
$("#clips").after('<ul id="slideshow-nav"><li><a id="gallery-next" href="#" title="View the next piece">Next</a></li><li><a id="gallery-prev" href="#" title="View the previous piece">Prev</a></li></ul>')
虽然在'用于界定HTML / XML中的属性值的Javascript使用中'和'用法可互换是很常见的,但很少见。
答案 2 :(得分:1)
我无法在FF3.5中重现该错误。
<div id="clips">test</div>
<script type="text/javascript">
$("#clips").after("<ul id='slideshow-nav'><li><a id='gallery-next' href='#' title='View the next piece'>Next</a></li><li><a id='gallery-prev' href='#' title='View the previous piece'>Prev</a></li></ul>");
</script>
给了我:
<div id="clips">test</div>
<ul id="slideshow-nav">
<li><a title="View the next piece" href="#" id="gallery-next">Next</a></li>
<li><a title="View the previous piece" href="#" id="gallery-prev">Prev</a></li>
</ul>
答案 3 :(得分:1)
在FF 3.5.2中为我工作正常。你在$(function(){})中包装它吗?确保加载DOM?
<html>
<head>
<title>tt</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
<script type="text/javascript">
$(function() {
$("#clips").after("<ul id='slideshow-nav'><li><a id='gallery-next' href='#' title='View the next piece'>Next</a></li><li><a id='gallery-prev' href='#' title='View the previous piece'>Prev</a></li></ul>");
});
</script>
</head>
<body>
<div id='clips'></div>
</body>
</html>
答案 4 :(得分:0)
看起来不错。一些事情要尝试:
重构以提高可读性(使用带有.join('')的数组的代码相同):
$("#clips")
.after( [
"<ul id='slideshow-nav'>",
"<li><a id='gallery-next' href='#' title='Next piece'>Next</a></li>",
"<li><a id='gallery-prev' href='#' title='Previous piece'>Prev</a></li>",
"</ul>"
].join('')
);
重命名id只是为了确保页面上没有冲突(通常有奇怪的错误):
$("#clips")
.after( [
"<ul id='slideshow-nav2'>",
"<li><a id='gallery-next2' href='#' title='Next piece'>Next</a></li>",
"<li><a id='gallery-prev2' href='#' title='Previous piece'>Prev</a></li>",
"</ul>"
].join('')
);
使用所有双引号和转义字符:
$("#clips")
.after( [
"<ul id=\"slideshow-nav2\">",
"<li><a id=\"gallery-next2\" href=\"#\" title=\"Next piece\">Next</a></li>",
"<li><a id=\"gallery-prev2\" href=\"#\" title=\"Previous piece\">Prev</a></li>",
"</ul>"
].join('')
);
答案 5 :(得分:0)
嗯,这对我有用吗?
答案 6 :(得分:0)
单引号和双引号在JavaScript和HTML中均有效:
HTML: “Double style quotes are the most common, but single style quotes are also allowed.”
JavaScript的: “A string literal is zero or more characters enclosed in single or double quotes.”