SharePoint Web部件上的jQuery.hover无法正常工作
我正在开发一个由SharePoint列表驱动的导航栏。 除了我的.hover
事件之外,一切都按预期工作。
编辑:我改变了我的代码行:
$('table').hover(function () { alert(this.id); });
我注意到,每当我在Header标签上盘旋时,警报消息都是空白的。 这让我相信它甚至没有归还ID。 然而,为父元素返回ID(
)…..我必须做一些愚蠢的事情。
当我有这个,它的工作原理:
$(document).hover(function () { alert(); });
但是,当我有这个时,没有任何反应:
$("#Header0").hover(function () { alert(); });
有任何想法,为什么这在SharePoint中不起作用,但如果我只是做一个常规的Web应用程序?
这是我的所有代码:
/////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////// ////////////////////////////////////////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(""); 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("" + HeaderDisplay[i] + "::::::" + " | "); } } 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: "", // completefunc: function completeFunction(xData, Status) { // $(xData.responseXML).SPFilterNode("z:row").each(function () { // var Headers = "" + $(this).attr("ows_Title") + " | "; // $("#TableElement").append(Headers); // }); // } // }); //});
尝试做这样的事……
$('#TableElement').hover(function () { $('#Header0').hover(function () { $('#Header2').append("" + this.id + ""); }); });
我怀疑这不起作用,因为jQuery无法“找到”ID。 一旦进入父母,它应该拿起它。