jquery mobile - 从另一个页面运行函数而不禁用ajax

时间:2022-08-24 11:17:39

i have two page test1.php and test2.php when i click on my button for going to test2.php my function not running in test2.php only if i put data-ajax="false" in said button it working but i want without disable ajax .. Is there a way ?

我有两个页面test1.php和test2.php,当我点击我的按钮进入test2.php我的功能没有在test2.php中运行只有我把数据-ajax =“false”在所述按钮中工作但我想要没有禁用ajax ..有办法吗?

test1.php

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

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>

1 个解决方案

#1


0  

If you want to run an external function, you can just create a file, let's call it myfunction.js. Then you add it below you jquery includes, like this:

如果你想运行一个外部函数,你可以创建一个文件,我们称之为myfunction.js。然后你在jquery包含下面添加它,如下所示:

...
<script src="//code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js">
<script src="myfunction.js"></script>

And in "myfunction.js" you add this:

在“myfunction.js”中添加以下内容:

$("a").click(function(){
  alert("Hi");
});

Kind of like I did in here: https://jsfiddle.net/uzt27mm2/ just call the script from an external .js file.

有点像我在这里做的:https://jsfiddle.net/uzt27mm2/只需从外部.js文件调用脚本。

#1


0  

If you want to run an external function, you can just create a file, let's call it myfunction.js. Then you add it below you jquery includes, like this:

如果你想运行一个外部函数,你可以创建一个文件,我们称之为myfunction.js。然后你在jquery包含下面添加它,如下所示:

...
<script src="//code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js">
<script src="myfunction.js"></script>

And in "myfunction.js" you add this:

在“myfunction.js”中添加以下内容:

$("a").click(function(){
  alert("Hi");
});

Kind of like I did in here: https://jsfiddle.net/uzt27mm2/ just call the script from an external .js file.

有点像我在这里做的:https://jsfiddle.net/uzt27mm2/只需从外部.js文件调用脚本。