将JQuery .load()转换为变量或隐藏元素 [英] JQuery .load() into variable or hidden element
问题描述
我将数据从一个页面的一部分拉到另一个页面以构建菜单。我需要将数据拉入隐藏的元素或变量,因为我现在最终得到了一个重复的菜单。我的动态飞出并且静态< ul>< li>
了。菜单由这些菜单构成。
I am pulling data from a section of one page into another in order to build a menu. I need to pull the data into a hidden element or variable as right now I end up with a duplicate menu. My dynamic fly out and the static <ul><li>
's. The menu is built of of these.
以下是我目前的情况:
<script type="text/javascript">
$(document).ready(function(){
$('div.ms-quickLaunch').replaceWith('<div id="hierarchy" style="border:solid 1px white; width:0px; visibility:hidden"></div>');
});
$(function(){
$('#hierarchy').load('http://wwcshare/icenter/Pages/wwcMenuContent.aspx #menuContent',
function(){
$(this).menu({
autoShow: true,
content: $(this).html(),
backLink: false,
crumbDefaultText: ' '
});
});
});
</script>
除了我的菜单不再被放置在它所属的位置之外,这是有效的。它位于页面的顶部而不是 #hierarchy div
。
This works except that my menu is no longer getting placed where it belongs. It is at the top of the page instead in side the #hierarchy div
.
这是我基于答案之一的替代尝试:
Here is my ALTERNATE ATTEMPT based on one of the answer's:
$(function(){
$.get('http://wwcshare/icenter/Pages/wwcMenuContent.aspx', function(data){ // grab content from another page
contentIwant = data.find("#menuContent");
$('#hierarchy').menu({
autoShow: true,
content: contentIwant,
backLink: false,
crumbDefaultText: ' '
});
});
});
推荐答案
$ .get()更适合您的目的使用$ .get()而不是$ .load()
a $.get() would suit your purposes better than a $.load()
您可以在将数据加载到页面之前处理数据
using $.get() you can process the data before loading it into the page
这篇关于将JQuery .load()转换为变量或隐藏元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!