Javascript 如果jquery脚本正在另一个php页面的php include语句中使用,为什么不运行它?
我正在使用javascript和php跨页面设置和获取cookie。我有一个脚本,它在一个页面上的cookie变量中放入一个值,我想在另一个页面上检索它。假设我的第一个页面叫做page1.html。在第1页中,我使用脚本存储cookie值,如下所示:Javascript 如果jquery脚本正在另一个php页面的php include语句中使用,为什么不运行它?,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我正在使用javascript和php跨页面设置和获取cookie。我有一个脚本,它在一个页面上的cookie变量中放入一个值,我想在另一个页面上检索它。假设我的第一个页面叫做page1.html。在第1页中,我使用脚本存储cookie值,如下所示: <Script> $(function () { $("#country-selector").change(function(){ $.cookie("Ron","Happy Birt
<Script>
$(function () {
$("#country-selector").change(function(){
$.cookie("Ron","Happy Birthday");
});
});
</script>
include('page1.html');
注意:Page1.html只做一件事。。。它有一个国家的下拉列表。如果我将浏览器直接指向page1.html并选择一个国家,则会设置cookie变量。但是,如果通过page2.php使用下拉列表,则不会设置cookie变量。我在浏览器设置中检查cookie列表以进行更改
如果脚本正在另一页的include语句中使用,那么什么会阻止脚本运行
为清晰起见,更新了:
Page1.php:
<!DOCTYPE html>
<html>
<head>
<?php session_start();?>
<script src="jquery-1.11.1.min.js"></script>
<script src="jquery.cookie.js"></script>
<script src="jquery-ui.min.js"></script>
<script src="jquery.select-to-autocomplete.js"></script>
<link rel="stylesheet" href="jquery-ui.css">
</head>
<body>
<select class="myList" name="Country" id="country-selector" autofocus="autofocus" autocorrect="off" autocomplete="off">
<option value="" selected="selected">Select Country</option>
<option value="Afghanistan" data-alternative-spellings="AF افغانستان">Afghanistan</option>
</select>
<Script>
$(function () {
$("#country-selector").change(function(){
$.cookie("Marry","Upside Down");
});
});
</script>
</body>
</html>
Page2.php
<html>
<head>
<script src="jquery-1.11.1.min.js"></script>
<script src="jquery-ui.min.js"></script>
<script src="jquery.select-to-autocomplete.js"></script>
<script type="text/javascript" </script>
<script src="jquery.cookie.js"></script>
</head>
<body>
<?php include ("page1.php"); ?>
</body>
</html>
除了加载jquery插件的顺序之外,我的代码很好。jquery.cookie.js应该最后加载。我建议发布更多相关的源代码,我们这里没有太多需要处理的内容,只有假设。给我们一些调试的东西,它可能会有帮助,但我们不能帮助从没有工作。我更新了清晰的帖子…但我发现我的问题。它很好用。我只需要记住在jquery-1.11.1.min.js之后加载jquery cookie的插件。在这种情况下,顺序是必要的。那么,你要在一个完整的html页面中间包含一个完整的html页面?对我来说似乎有点无效。您多次包含相同的javascript文件。另外,第2页似乎有一个打字错误。