如何防止在Sharepoint web部件的编辑模式下运行jQuery?
我正在使用Sharepoint 2010构建一个网站,并在内容编辑器Web部件中创建了一个时髦的jQuery幻灯片(使用查看HTML代码编辑选项)。非常有效,除非我想编辑web部件,否则jQuery会在编辑屏幕上运行并造成各种破坏 我的HTML基本上是这样的:如何防止在Sharepoint web部件的编辑模式下运行jQuery?,jquery,sharepoint,sharepoint-2010,Jquery,Sharepoint,Sharepoint 2010,我正在使用Sharepoint 2010构建一个网站,并在内容编辑器Web部件中创建了一个时髦的jQuery幻灯片(使用查看HTML代码编辑选项)。非常有效,除非我想编辑web部件,否则jQuery会在编辑屏幕上运行并造成各种破坏 我的HTML基本上是这样的: <div class="slideshow"> <div class="slide">Slide 1</div> <div class="slide">Slide 2<
<div class="slideshow">
<div class="slide">Slide 1</div>
<div class="slide">Slide 2</div>
</div>
在编辑Sharepoint 2010 Web部件时,我是否可以依靠某个类或id来防止jQuery选择器看到我的幻灯片?大概是这样的:
$('.slideshow').each(function(){
// Do the magic
});
$('div:not(.sharepoint-edit-block) .slideshow').each(function(){
// Do the magic
});
在wiki页面上,您可以检查ID为
\u wikiPageMode
的元素,如果您处于编辑模式,值
属性将为编辑
,否则它将为空(空字符串)
如果您不在wiki页面上,则可以查找ID为MSOLayout\u InDesignMode
的表单元素,如果您处于编辑模式,则值
属性将为1
,否则它将为空(空字符串)。Wiki页面也有此标记,但当Wiki页面处于编辑模式时,它的值未设置为1。非Wiki页面将没有\u wikiPageMode
标记,因此您的选择器将为空(一个没有结果的数组),对val()
的调用将是未定义的
// technique for wiki pages
$("#_wikiPageMode").val() // "Edit" or ""
// technique for non-wiki pages
$("#MSOLayout_InDesignMode").val() // "1" or ""
在wiki页面上,您可以检查ID为\u wikiPageMode
的元素,如果您处于编辑模式,值
属性将为编辑
,否则它将为空(空字符串)
如果您不在wiki页面上,则可以查找ID为MSOLayout\u InDesignMode
的表单元素,如果您处于编辑模式,则值
属性将为1
,否则它将为空(空字符串)。Wiki页面也有此标记,但当Wiki页面处于编辑模式时,它的值未设置为1。非Wiki页面将没有\u wikiPageMode
标记,因此您的选择器将为空(一个没有结果的数组),对val()
的调用将是未定义的
// technique for wiki pages
$("#_wikiPageMode").val() // "Edit" or ""
// technique for non-wiki pages
$("#MSOLayout_InDesignMode").val() // "1" or ""
我没有使用在另一个答案中提到的隐藏输入ID,但它们是存在的,并且同样有效
假设是一个发布页面,我总是使用以下内容
$(document).ready(function(){
// Only run if page is not in Design Mode
var inDesignMode = document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value;
if (inDesignMode !== "1")
{
$('.slideshow').each(function(){
// Do the magic
});
}
});
我没有使用在另一个答案中提到的隐藏输入ID,但它们是存在的,并且同样有效
假设是一个发布页面,我总是使用以下内容
$(document).ready(function(){
// Only run if page is not in Design Mode
var inDesignMode = document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value;
if (inDesignMode !== "1")
{
$('.slideshow').each(function(){
// Do the magic
});
}
});
$(“#MSOLayout_InDesignMode”).val()/“1”或“
在SharePoint Office 365中为我工作。听起来很明显,但请检查字符串值“1”而不是数字1。$(“#MSOLayout_InDesignMode”).val()/“1”或“
在SharePoint Office 365中对我有效。听起来很明显,但请检查字符串值“1”而不是数字1。