如果jquery脚本's在另一个php页面的php-include语句中使用
Why does a jquery script not run if it's being used in a php include statement from another php page?
我使用javascript和php来设置和获取跨页面的cookie。我有一个脚本,它在一个页面的cookie变量中放入一个值,我想在另一个页面上检索它。假设我的第一个页面叫做page1.html。在page1中,我使用一个脚本来存储一个cookie值,如下所示:
<Script>
$(function () {
$("#country-selector").change(function(){
$.cookie("Ron","Happy Birthday");
});
});
</script>
现在假设我有一个名为page2.php的页面。在page2.php中,我有一条include语句,它加载page1.html,如下所示:
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应该最后加载。
相关文章:
- 如何从php onclick语句中获取值
- jade/pug是否可以在include语句中使用变量
- 在 HTML 代码中调用 PHP 函数,在 PHP echo 语句中
- PHP if语句中的Jquery
- 使用JS'更正语法;onclick'PHP echo语句中的函数与嵌入的XML获取进行AND
- PHP if语句中的Javascript
- 如果jquery脚本's在另一个php页面的php-include语句中使用
- 有没有其他方法可以在远程服务器上包含php文件?除了<?php include()>
- Javascript AJAX PHP if语句不起作用
- 我可以在Drupal 7的jquery脚本中有一个php if语句吗?
- 在 php include 中运行 Javascript
- 当变量写在 PHP echo 语句中时,如何通过 JavaScript 函数传递变量
- jQuery没有使用php include运行
- 在 php if 语句中使用 javascript 变量
- 将变量从javascript传递给php get语句
- 尝试通过php include放置png图像..这怎么可能
- 带有2个条件的PHP IF语句
- 基于屏幕大小的PHP if语句
- 如何使用JQuery或AJAX添加php-include语句
- 从jquery ajax调用php函数时出现include语句错误