Jquery 页面刷新可防止将HTML附加到DOM
我有一个悬停菜单,但由于移动设备上的悬停限制(用户无法单击页面并在页面刷新时将菜单保留在屏幕上,因为它在页面刷新时消失),我创建了以下函数,该函数应使他们能够执行此操作。但是,当页面刷新时,菜单不会附加到DOM中(在页面刷新之前,我可以在屏幕上看到它一瞬间)。你知道为什么吗Jquery 页面刷新可防止将HTML附加到DOM,jquery,css,html,Jquery,Css,Html,我有一个悬停菜单,但由于移动设备上的悬停限制(用户无法单击页面并在页面刷新时将菜单保留在屏幕上,因为它在页面刷新时消失),我创建了以下函数,该函数应使他们能够执行此操作。但是,当页面刷新时,菜单不会附加到DOM中(在页面刷新之前,我可以在屏幕上看到它一瞬间)。你知道为什么吗 $('ul.dropdown').empty().append(localStorage.getItem("listHTML")); 作用- <script> $(document).ready(fun
$('ul.dropdown').empty().append(localStorage.getItem("listHTML"));
作用-
<script>
$(document).ready(function () {
//on mobile only due to hover limitations -
//(we desire to click a parent menu link that goes to its homepage AND show the hover menu that was clicked and its children)
//therefore we want to send the user to the homepage of the clicked menu item (parent)
//AND display its sub menu items (children) again in a menu.
if ($(window).width() <= 939) {
$("li.sub-level").click(function () {
if (typeof (Storage) !== "undefined") {
var listHTML = $(this).find(".dropdown").html();
var nodeTITLE = $(this).children().clone().html();
localStorage.setItem("listHTML", listHTML);
localStorage.setItem("nodeTITLE", nodeTITLE);
//test stubs
alert(listHTML);
alert(nodeTITLE);
}
else {
alert('Your browser does not support HTML5 storage, please report this.')
}
//at this point remove the class that stops this link from executing the anchor and take the user to target page
$(this).removeClass("has-dropdown");
//alert('about to write the listHTML into the DOM');
//now finally append the listHTML to the menu as the page has refreshed -
//NOT WORKING AS PAGE REFRESH WIPING OUT THE HTML!
$('ul.dropdown').empty().append(localStorage.getItem("listHTML"));
});
}
});
</script>
$(文档).ready(函数(){
//仅因悬停限制而在移动设备上-
//(我们希望单击指向其主页的父菜单链接,并显示单击的悬停菜单及其子菜单)
//因此,我们希望将用户发送到单击菜单项(父项)的主页
//并在菜单中再次显示其子菜单项(子菜单)。
如果($(window).width()追加时,localStorage.getItem(“listHTML”)
的值是多少,则新的listHTMLHi保留已将提取的HTML添加到已编辑的帖子中,但仍缺少一些上下文(例如.sub-level和.dropdown元素)Hi Kees.sub-level是上一级的,并且已经修改了HTMLOK,我现在就知道了:)当你追加时,localStorage.getItem(“listHTML”)
的值是多少,然后新的listHTMLHi Kees提取的HTML已经添加到编辑过的帖子Hi-Bob上面,仍然缺少一些上下文(例如.sub-level和.dropdown元素)嗨,Kees。子级别提高了一个级别,并且已经修改了HTMLOK。我现在明白了:)
<ul class="dropdown"><li class="title back js-generated"><h5><a href="#">Back</a></h5></li>
<li>
<a href="http://scotsman.v6hotelsites.local/scotsman-hotel/about/" target="">
Introducing the Scotsman
</a>
</li>
<li>
<a href="http://scotsman.v6hotelsites.local/scotsman-hotel/about/history/" target="_self">
History
</a>
</li>
<li>
<a href="http://scotsman.v6hotelsites.local/scotsman-hotel/about/concierge/" target="_self">
Concierge
</a>
</li>
<li>
<a href="http://scotsman.v6hotelsites.local/scotsman-hotel/about/location/" target="_self">
Location
</a>
</li>
<li>
<a href="http://scotsman.v6hotelsites.local/scotsman-hotel/about/hotel-services/" target="_self">
Hotel Services
</a>
</li>
</ul>