在jquery 1.9.1中创建变量失败,而在1.8.3中没有 [英] Making a variable in jquery 1.9.1 fails and in 1.8.3 doesn't
问题描述
我刚刚升级到1.9.1 经过一些技术上的缺陷后,所有工作都可以进行,除了:
I just upgraded to 1.9.1 After some technical defiificulties all work except:
var $newthumbs = $(' <div id=\"car-7\" class=\"thumbnail_car thumbnail span2\" data-sorting-top=\"2\" data-sorting-date=\"2013-01-12 16:47:31 UTC\"></div>');
如果我将此行放在jquery 1.8.3的控制台中,它将被接受,并且可以使用$ newthumbs检索它.
If I put this line in the console of jquery 1.8.3 it gets accepted and I can retrieve it with $newthumbs
在1.9.1中失败,并显示Error: Syntax error, unrecognized expression:
in 1.9.1 it fails with Error: Syntax error, unrecognized expression:
我已阅读更改日志并且我看不到任何可以打破这一点的东西.我可能不太了解jquery,但是这种语法看起来很标准.
I've read the changelog and I don't see anything relating that should break this. I may not know a lot of jquery, but this type of syntax looks standard.
发生了什么变化?
更新
我确实在此处
带有领先空格的HTML字符串:jQuery 1.9限制了字符串 出于安全原因由$()处理.虽然我们建议您使用 $ .parseHTML()用于处理模板等任意HTML,即1.1.0 版本的Migrate插件可还原旧的行为.
HTML strings with leading whitespace: jQuery 1.9 restricts the strings processed by $() for security reasons. Although we recommend you use $.parseHTML() to process arbitrary HTML like templates, the 1.1.0 version of the Migrate plugin restores the old behavior.
推荐答案
如果删除空格,它将起作用:
If you remove the spaces, it will work:
var $newthumbs = $('<div id=\"car-7\" class=\"thumbnail_car thumbnail span2\" data-sorting-top=\"2\" data-sorting-date=\"2013-01-12 16:47:31 UTC\"></div>');
演示: http://jsfiddle.net/dirtyd77/KFmMQ/1/
这篇关于在jquery 1.9.1中创建变量失败,而在1.8.3中没有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!