jQuery mobile.load()之后的无点击事件
如果我将一个页面加载到“curr_recipe”中,并希望返回页脚中指向#home的链接,则页面#home上不再有可用的点击事件;jquery代码来自m-index.php,我使用的是用户代理功能,因为我希望在移动设备和pc/笔记本电脑等上显示此页面jQuery mobile.load()之后的无点击事件,jquery,jquery-mobile,mobile,hyperlink,load,Jquery,Jquery Mobile,Mobile,Hyperlink,Load,如果我将一个页面加载到“curr_recipe”中,并希望返回页脚中指向#home的链接,则页面#home上不再有可用的点击事件;jquery代码来自m-index.php,我使用的是用户代理功能,因为我希望在移动设备和pc/笔记本电脑等上显示此页面 $(document).ready(function () { $("#btnSearch").click(function() {searchFiles()}); $("#testrecipe").click(f
$(document).ready(function () {
$("#btnSearch").click(function() {searchFiles()});
$("#testrecipe").click(function() {
$.mobile.changePage("#actRecipe");
$("#curr_recipe").load("htmltodisplay.html", function() {
$.mobile.changePage("#home", {transition: "fade"});
});
});
$("#btnReset").click(function() {resetInput()});
$("#txtRecipe").click(function() {resetInput()});
$("#toSearch").click(function() {$.mobile.changePage("#searchPage", {transition: "slide"})});
$("#allrecipes").click(function() {
$.mobile.changePage("#recipePage", {transition: "slide"});
readFiles(true);
});
});
<div data-role="page" id="home">
<div data-role="header">
<h1>Head</h1>
</div>
<div data-role="content">
<h1>What to do?</h1>
</div>
<div class="nav">
<ul style="font-size:24px;" data-role="listview">
<button id="toSearch">Rezept suchen</button>
<button id="allrecipes">Alle Rezepte</button>
<button id="testrecipe">Test Rezept</button>
</ul>
</div>
</div>
<div data-role="page" id="actRecipe">
<div id="curr_recipe" data-role="content">
</div>
<div data-role="footer" data-position="fixed" data-id="oneFooter">
<a style="font-size: 24px; width: 100%; border-radius: 0px;" href="#home" data-transition="fade">Menü</a>
</div>
</div>
$(文档).ready(函数(){
$(“#btnSearch”)。单击(函数(){searchFiles()});
$(“#测试配方”)。单击(函数(){
$.mobile.changePage(“actRecipe”);
$(“#curr_recipe”).load(“htmltodisplay.html”,function(){
$.mobile.changePage(“#home”{transition:“fade”});
});
});
$(“#btnReset”)。单击(函数(){resetInput()});
$(“#txtRecipe”)。单击(函数(){resetInput()});
$(“#toSearch”)。单击(函数(){$.mobile.changePage(“#searchPage”,{转换:“幻灯片”}));
$(“#所有配方”)。单击(函数(){
$.mobile.changePage(“#recipePage”,{transition:“slide”});
readFiles(true);
});
});
头
怎么办?
雷泽普特苏晨
阿勒雷泽普特酒店
测试结果
要加载的页面
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="./jquery-2.0.0.js"></script>
<link type="text/css" rel="stylesheet" media="screen" href="./css/recipe_screen.css" />
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
<title></title>
<script>
$(document).ready(function() {
var UserAgent = navigator.userAgent.toLowerCase();
if (UserAgent.search(/(iphone|ipod|opera mini|fennec|palm|blackberry|android|symbian|series60)/) > -1) {
// mobiles Endgerät
document.getElementById("back").style.display = "none";
} else {}
});
</script>
</head>
<body>
<div id="title"></div>
<h2 class="rphone"></h2>
<div class="content">
<ul id="ingredients">
</ul>
</div>
<h2 class="rphone"> </h2>
<div class="content" id="cooking">
</div>
<div id="back">
<a id="linkback" href="/rezepteV1/index.php">Zum Menü</a>
</div>
</body>
</html>
$(文档).ready(函数(){
var UserAgent=navigator.UserAgent.toLowerCase();
if(UserAgent.search(/(iphone | ipod | opera mini | fennec | palm | blackberry | android | symbian | series60)/)>1){
//移动电话公司
document.getElementById(“back”).style.display=“无”;
}else{}
});
编辑:
您检查了()上的jquery了吗
假设事件无法激发,因为元素当时不存在。使用on(),您可以等待它,这样无论发生什么情况,它都可以随时被触发。您需要向load()添加回调。实际上,只有在load()完成时才会执行回调。请确保加载的.html文件中没有错误。例如,标记未关闭或该文件中的click事件。html文件中没有错误,我添加了一个回调:$(“#testrecipe”)。单击(function(){$.mobile.changePage(“#actRecipe”);$(“#curr#recipe”)。load(“anypage.html”,function(){$.mobile.changePage(“#home“,{transition transition:“fade”});});但是仍然存在同样的问题,我可以看到主页,但是在我重新加载页面之前我无法“交互”。你能发布你的页面结构吗?也许你有重复的id?我发布了我的结构,但你想看到我的其他页面吗?对不起,我不知道如何/:你能提供更多的代码吗?也许问题不在你认为的地方你的意思是我应该用jquery on()替换主页上的按钮点击事件?对不起,这是我第一个使用jquery的项目!好的,我试试看你不必感到抱歉;)