这是我在index.html中的代码,我调用.load来加载整个artists.html 使用id脚本编写div。这一切都发生在index.html中,页面加载正常。
$j("#artists").click(function(e) {
e.preventDefault(); // if desired...
$j( "#scriptin" ).load( "artists.html" );
问题在于artist.html中的javascript。在调用.load()之后加载页面时似乎没有执行。当我用直接链接打开它时,它工作正常。
<script>
$(document).ready(function() {
$('.animate').mouseenter(function() {
$(this).css("opacity",1);
})
$('.animate').mouseleave(function() {
$(this).css("opacity",0.8);
})
})
</script>
答案 0 :(得分:0)
artist.html中的脚本是否位于该页面的head标记内?从jquery文档:
jQuery使用浏览器的.innerHTML属性来解析检索到的 记录并将其插入当前文档。在此过程中, 浏览器经常过滤文档中的元素,如html, 标题或头元素。结果,检索到的元素 .load()可能与检索文档时不完全相同 直接通过浏览器。
将您的脚本移动到artists.html文件的正文中,脚本应该在您在那里定义的内容时运行。