我有一个包含jQuery和JavaScript的超文本标记语言页面。我将在head标记中导入所需的库:
<link rel="stylesheet" href="http://code.jquery.com/ui/1.8.18/themes/base/jquery-ui.css" type="text/css" media="all" />
<link rel="stylesheet" href="http://static.jquery.com/ui/css/demo-docs-theme/ui.theme.css" type="text/css" media="all" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="http://code.jquery.com/ui/1.8.18/jquery-ui.min.js" type="text/javascript"></script>
<script src="http://jquery-ui.googlecode.com/svn/tags/latest/external/jquery.bgiframe-2.1.2.js" type="text/javascript"></script>
<script src="http://jquery-ui.googlecode.com/svn/tags/latest/ui/minified/i18n/jquery-ui-i18n.min.js" type="text/javascript"></script>
<script src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places" type="text/javascript"></script>
然后,我将导入一些内部带有jQuery的html:
$('#cliente').click(function(){$('#container').load('/clienti/cliente');});
但是加载的页面内的jQuery不起作用。(我确信代码是正确的,就像独立工作一样)。
我需要做点什么吗?我曾尝试在脚本之前导入导入页面中的库(从头部中),但不起作用。我没有别的想法了!
发布于 2012-05-23 00:14:44
.load()
only works for HTML你使用它的方式。(请参阅标题为“脚本执行”的小节)。它不会计算您加载的HTML中的任何脚本。您想要的是使用后缀加载它,即
$('#cliente').click(function(){$('#container').load('/clienti/cliente.html');});
发布于 2012-05-23 00:20:11
如果您的JS和HTML必须在同一个文件中,更好的方法是这样做。我相信它会以这种方式评估JS。
$('#cliente').click(function(){
$.get('/clienti/cliente', function(data){
$('#container').html(data);
});
});
或者,您可以将这两个项( HTML和JS)作为文本传回
$('#cliente').click(function(){
$.getJSON('/clienti/cliente', function(object){
$('#container').html(object.html);
$parseJSON(object.jscript);
});
});
否则,您将需要使用$.get()
和$.getJSON()
在两个快照中获取html和js。
https://stackoverflow.com/questions/10705870
复制相似问题