SharePoint Web部件上的jQuery.hover无法正常工作 [英] jQuery.hover on SharePoint Web Part not working

查看:103
本文介绍了SharePoint Web部件上的jQuery.hover无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用从SharePoint列表中删除的导航栏.除了我的.hover事件,一切都按预期进行.

I am working on a navigation bar that is driven off of a SharePoint List. Everything is working as expected except my .hover event.

我将代码行更改为此:

I changed my line of code to this:

$('table').hover(function () { alert(this.id); });

我注意到,每当我将鼠标悬停在标题标签上时,警报消息都是空白的.这使我相信,这甚至没有返回ID.但是ID会返回父元素(<table>)的ID .....我必须做一些愚蠢的事情.

I noticed that whenever I hovered over my Header Tags, the alert message was blank. This leads me to believe that's it's not even returning the ID. However the ID gets returned for the parent element (<table>).....I've got to be doing something stupid.

当我有此功能时,它会起作用:

When I have this, it works:

$(document).hover(function () { alert(); });

但是,当我有这个时,什么也没发生:

However, when I have this, nothing happens:

$("#Header0").hover(function () { alert(); });

有什么想法为什么在SharePoint中不起作用,但是如果我只是做常规的Web应用程序就起作用?

Any idea's as to why this doesn't work in SharePoint but works if I just do a regular web application?

这是我所有的代码:

    ///////////////////////////////////////////////////////////////////////////////////////////    //////////////////////////////////////////
////////////////////////////////////////EVERYTHING BELOW THIS LINE IS GOOD TO    GO/////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////    //////////////////////////////////////////
//Print Headers to Screen. This will drive the core functionalty of the navpart
var siteUrl = '/sites/dev';
ExecuteOrDelayUntilScriptLoaded(retrieveListItems, "sp.js");
theCounter = 0;
var Headers = new Array();
var getCurrentElementId = null;
function retrieveListItems() {
var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('myList');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml("<Where><IsNotNull><FieldRef Name='Title' /></IsNotNull></Where>");
this.collListItem = oList.getItems(camlQuery);
clientContext.load(collListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded),  Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded(sender, args) {
var listItemInfo = '';
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
    var oListItem = listItemEnumerator.get_current();
    theCounter += 1;
    Headers[theCounter - 1] = oListItem.get_item('Title');
}
var HeaderDisplay = _.uniq(Headers);
for (var i = 0; i <= HeaderDisplay.length - 1; i++) {
    $('#TableElement').append("<th id=Header" + i + ">" + HeaderDisplay[i] + "::::::" +  "</th>");
}
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

    ///////////////////////////////////////////////////////////////////////////////////////////    //////////////////////////////////////////
 ////////////////////////////////////////EVERYTHING ABOVE THIS LINE IS GOOD TO     GO/////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////////////////////    //////////////////////////////////////////


// You got the headers to print as expected. Right now you need to figure out how to get the current ID
// that the mouse is over. Try looking at another project you did where the mouse goes into the table header
// and the outline expands.


$("#Header0").hover(function () { alert(); });



//This should be the universal onmouseover event that will expose only links
//and values relavent to the selected header.

//$(document).ready(function onPageLoad() {
//    $().SPServices({
//        operation: "GetListItems",
//        async: false,
//        listName: "myList",
//        CAMLQuery: "<Query><Where><IsNotNull><FieldRef Name='Title' /></IsNotNull></Where></Query>",
//        completefunc: function completeFunction(xData, Status) {
//            $(xData.responseXML).SPFilterNode("z:row").each(function () {
//                var Headers = "<th>" + $(this).attr("ows_Title") + "</th>";
//                $("#TableElement").append(Headers);
//            }); 
//        }
//    });
//});

推荐答案

尝试做这样的事情...

Try doing something like this...

$('#TableElement').hover(function () {
$('#Header0').hover(function () {
    $('#Header2').append("<li>" + this.id + "</li>");
});
});

我怀疑这不起作用,因为jQuery无法找到" ID.一旦进入父级,它就应该捡起来.

I suspect this isn't working because jQuery couldn't 'find' the ID. Once inside the parent, it should pick it up.

这篇关于SharePoint Web部件上的jQuery.hover无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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