Javascript 点击图像主页是否应显示? $(文档).ready(函数(){ $('.floatLeftClass')。单击(函数(){ $(this.load('index.html'); }); });
//这是单击此索引页时应显示的图像我的脚本是请尝试以下操作:Javascript 点击图像主页是否应显示? $(文档).ready(函数(){ $('.floatLeftClass')。单击(函数(){ $(this.load('index.html'); }); });,javascript,jquery,Javascript,Jquery,//这是单击此索引页时应显示的图像我的脚本是请尝试以下操作: <html> </body> <div> <img class="floatLeftClass" id="float-Left-Class" src="images/logo.png" width="100" height="50"> </div> </body> </html> $(document).rea
<html>
</body>
<div>
<img class="floatLeftClass" id="float-Left-Class" src="images/logo.png"
width="100" height="50">
</div>
</body>
</html>
$(document).ready(function () {
$('.floatLeftClass').click(function(){
$(this).load( 'index.html' );
});
});
“load”函数是另一种功能——它将请求的资源加载到元素中(如
或类似的元素)
编辑:您可以在此处阅读.load()的文档:尝试此方法
$('.floatLeftClass').click(function(){
location.href = 'index.html';
});
此代码是否来自单个文件?如果是这样,请将您的javascript代码放入
和
中。是的,我已经完成了,但仍然无法工作。您可以告诉我们您项目的文件结构吗?您正在图像上调用.load()
,但它应该是某种容器,通常是
。然而,首先为什么要这样做?为什么不干脆
?我在同一页中使用脚本。带脚本标记
<div>
<a href="https://www.w3.org/"> // Your page URL
<img id="img" src="imgname.png" width="100" height="50">
</a>
</div>