jquery 移动设备 - 运行 来自另一个页面的功能没有禁用 ajax
jquery mobile - run function from another page without disable ajax
我有两个页面 test1.php
和 test2.php
当我点击我的按钮去 test2.php
我的功能不是 运行 在 test2.php
只有当我把 data-ajax="false"
放在它工作的所述按钮中,但我想要不禁用 ajax .. 有办法吗?
test1.php
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="//code.jquery.com/mobile/1.4.5/jquery.mobile-
1.4.5.min.css">
<script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="//code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js">
</script>
</head>
<body >
<div id="page-1" data-role="page" >
<div data-role="content">
<a href="test2.php">click</a>
</div>
</div>
</body>
</html>
test2.php
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="//code.jquery.com/mobile/1.4.5/jquery.mobile-
1.4.5.min.css">
<script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="//code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js">
</script>
</head>
<body >
<div id="page-1" data-role="page" >
<div data-role="content">
</div>
</div>
<script type="text/javascript">
$(function() {
alert("hi");
})
</script>
</body>
</html>
如果你想运行一个外部函数,你可以只创建一个文件,我们称之为myfunction.js。然后将其添加到 jquery 包含的下方,如下所示:
...
<script src="//code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js">
<script src="myfunction.js"></script>
然后在 "myfunction.js" 中添加:
$("a").click(function(){
alert("Hi");
});
有点像我在这里所做的:https://jsfiddle.net/uzt27mm2/ 只需从外部 .js 文件调用脚本。
我有两个页面 test1.php
和 test2.php
当我点击我的按钮去 test2.php
我的功能不是 运行 在 test2.php
只有当我把 data-ajax="false"
放在它工作的所述按钮中,但我想要不禁用 ajax .. 有办法吗?
test1.php
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="//code.jquery.com/mobile/1.4.5/jquery.mobile-
1.4.5.min.css">
<script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="//code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js">
</script>
</head>
<body >
<div id="page-1" data-role="page" >
<div data-role="content">
<a href="test2.php">click</a>
</div>
</div>
</body>
</html>
test2.php
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="//code.jquery.com/mobile/1.4.5/jquery.mobile-
1.4.5.min.css">
<script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="//code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js">
</script>
</head>
<body >
<div id="page-1" data-role="page" >
<div data-role="content">
</div>
</div>
<script type="text/javascript">
$(function() {
alert("hi");
})
</script>
</body>
</html>
如果你想运行一个外部函数,你可以只创建一个文件,我们称之为myfunction.js。然后将其添加到 jquery 包含的下方,如下所示:
...
<script src="//code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js">
<script src="myfunction.js"></script>
然后在 "myfunction.js" 中添加:
$("a").click(function(){
alert("Hi");
});
有点像我在这里所做的:https://jsfiddle.net/uzt27mm2/ 只需从外部 .js 文件调用脚本。