为什么jQuery函数不以预览模式加载?
jQuery函数没有在Sitecore预览模式下加载,但在Experience Editor中工作正常,如何解决此问题?我还附上了一张图片。为什么jQuery函数不以预览模式加载?,jquery,asp.net,sitecore,sitecore8,Jquery,Asp.net,Sitecore,Sitecore8,jQuery函数没有在Sitecore预览模式下加载,但在Experience Editor中工作正常,如何解决此问题?我还附上了一张图片。 您需要在无冲突模式下运行jQuery。有关详细信息,请参阅本文: 要在无冲突模式下运行jQuery,您可以如下方式包装脚本: (function ($) { ... })(jQuery); <!-- Putting jQuery into no-conflict mode. --> <script src="prototype.
您需要在无冲突模式下运行jQuery。有关详细信息,请参阅本文: 要在无冲突模式下运行jQuery,您可以如下方式包装脚本:
(function ($) {
...
})(jQuery);
<!-- Putting jQuery into no-conflict mode. -->
<script src="prototype.js"></script>
<script src="jquery.js"></script>
<script>
var $j = jQuery.noConflict();
// $j is now an alias to the jQuery function; creating the new alias is optional.
$j(document).ready(function() {
$j( "div" ).hide();
});
// The $ variable now has the prototype meaning, which is a shortcut for
// document.getElementById(). mainDiv below is a DOM element, not a jQuery object.
window.onload = function() {
var mainDiv = $( "main" );
}
</script>
或者像这样设置jquery:
(function ($) {
...
})(jQuery);
<!-- Putting jQuery into no-conflict mode. -->
<script src="prototype.js"></script>
<script src="jquery.js"></script>
<script>
var $j = jQuery.noConflict();
// $j is now an alias to the jQuery function; creating the new alias is optional.
$j(document).ready(function() {
$j( "div" ).hide();
});
// The $ variable now has the prototype meaning, which is a shortcut for
// document.getElementById(). mainDiv below is a DOM element, not a jQuery object.
window.onload = function() {
var mainDiv = $( "main" );
}
</script>
var$j=jQuery.noConflict();
//$j现在是jQuery函数的别名;创建新别名是可选的。
$j(文档).ready(函数(){
$j(“div”).hide();
});
//$变量现在具有原型含义,这是
//document.getElementById()。下面的mainDiv是一个DOM元素,而不是jQuery对象。
window.onload=函数(){
var mainDiv=$(“主”);
}
学分:
这篇文章还回答了一个类似的问题:jQuery破坏了你的预览。使用js.noConflict(),加载新的jquery min后,jsI更喜欢将错误作为文本而不是图像…确保您的js库以预览模式加载。不确定OP使用的是哪个版本,但是,FWIW,8.1问题($variable已由体验编辑器初始化-jquery兼容性问题。此问题已修复。)