2015-10-19 56 views
0

下面的代码在我的第一个PHP文件上运行良好,但是当我加载另一个文件并使用相同的脚本时,它看起来不起作用,我没有从alert (idstate);得到警报。 CSS/HTML工作正常。脚本不能在php页面之间工作

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 
<script> 
$(document).ready(function(){ 
    $("li").click(function(){ 
     if (event.target.id!=""){ 

      var idstate=(event.target.id) 
      alert (idstate); 

      $.post("somepage.php", { variable: idstate}, function(data) 
      { 
       alert(data); 
      }); 
     } 
    }); 
}); 
</script> 
+2

为什么这个标记为“PHP”,如果它内部没有“PHP”代码?还指定了哪个“事件”? – Script47

+0

就像我说我是一个新手,我只给脚本,因为它在我的第一个(PHP)页面上工作,然后它在新页面上失败,jquery从谷歌上加载这两个页面 –

+0

它可能是值得发布的这两个页面的HTML问题 - 或者创建一个[JS小提琴](http://jsfiddle.net)来说明问题。 – bunnmatt

回答

0

当你加载另一个文件,你必须链接到你的PHP页面。 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script> <script src="path/custom.js"></script>

+0

已加载到两页 –