如何在SharePoint Web部件中正确使用jquery-jquery并不总是会触发 [英] How to use jquery correctly in SharePoint Web Part - jquery doesn't always fire

查看:67
本文介绍了如何在SharePoint Web部件中正确使用jquery-jquery并不总是会触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习如何在SharePoint中使用jquery.选择链接后,我的示例在内容编辑器" Web部件内绘制了一个红色框.当SharePoint页面处于编辑模式时,我的代码可以工作,但是当我离开页面并返回非编辑模式时,我的代码无法工作. jQuery函数由于某种原因而无法触发...我错过了一些简单但不确定的内容.

I'm learning how to use jquery with SharePoint. My example draws a red box inside the Content Editor Web Part when a link is selected. My code works when the SharePoint page is in edit mode but not after I've left the page and returned in non edit mode. The jquery function does not fire for some reason... I'm missing something simple but not sure what.

感谢您的帮助.

凯文

我的网站主页通过以下方式连接到jquery-1.3.2.min.js文件:

My master page for the site connects to the jquery-1.3.2.min.js file this way:

 <SharePoint:ScriptLink language="javascript" name="jquery-1.3.2.min.js" 
 Defer="true" runat="server"/>

我的内容编辑器Web部件代码如下:

My Content Editor Web Part code looks like this:

<style type="text/css">
#box
{
    background: red;
    width: 300px;
    height: 300px;
    display: none;
}
</style>


<script type ="text/javascript">
    $(function() {
        $('a').click(function() {
            $('#box').slideDown(2000);
        });
    })
</script>

<div id="box">
<h1>This is text in the box</h1>
</div>
<a href="#">Display Box</a><br />

推荐答案

检查ScriptLink控件的渲染HTML,看看是否可以浏览到< script>给出的位置.标签.这应该使您对发生的问题有所了解.

Check the rendered HTML for the ScriptLink control and see if you can browse to the location given by the <script> tag. This should give you some ideas about what's going wrong.

此外,请查看此问题,其中包含用于将jQuery添加到的选项SharePoint. (免责声明:答案之一是我的以及我当前使用的方法.)

Also, have a look at this question which contains options for adding jQuery to SharePoint. (Disclaimer: one of the answers is mine and the method I currently use.)

这篇关于如何在SharePoint Web部件中正确使用jquery-jquery并不总是会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆