jquery将无法在java select include检索的文件中工作

我有一个简单的表单,当更改时包括div中的php文件。 由于某些原因,jquery放置在包含的文件中时不会加载? 有人能告诉我为什么这不起作用。

 the file  
Where the file is loaded and where jquery wont work
function show(str) { if (str=="") { document.getElementById("make").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("make").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","include/some-file.php?q="+str,true); xmlhttp.send(); }

然后some-file.php

  $models = mysql_query("SELECT model, id FROM model where make like '%".$q."%' order by model asc") or die(mysql_error()); //Puts it into an array $count = 1; $max = 3; while($model = mysql_fetch_array( $models )) { if($count%20==1) echo '
    '; echo "
  • ".$count.". ".$model['model']." x
  • "; $(docuument).ready(function() { $(".delete-model").click(function() { alert("delete"); }); }); $count++; } ?>

我有同样的问题……

要解决这个问题,你需要做的就是使用普通的JavaScript编辑ajax到$.ajax所以使用jQuery来处理它..它会工作..

 $.ajax({ url: "include/some-file.php?q="+str, type: "GET", datatype: 'html', success: function(e){ $('#make').html(e); } }); 

我不确定,因为代码不完整,我的猜测就是你要导入的someotherphp文件中使用的是document.ready函数,因为你使用ajax加载文件而没有调用。

使用ajax加载的脚本或者通常在DOM中注入的脚本字符串将不会出于安全原因而执行

你可以使用eval让它工作,虽然我必须警告你,你可以打开一jar蠕虫..

document.getElementById("make").innerHTML=xmlhttp.responseText; 加上这个..

 var parent = document.getElementById('make'); var myScript = parent.getElementsByTagName('script'); for(var i=0,len=myScript.length; i 

那么执行function......

  function executeScrpt(scrpt){ if(scrpt.innerHTML != ""){ eval("("+script.innerHTML+")"); } else { if(scrpt.src != ""){ var myScrpt = document.createElement("script"); myScrpt.src = scrpt.src; document.head.appendChild(myScrpt); } } }