当我点击 img 时,我在 Firefox 的控制台中不断收到 ReferenceError:toggleExpand is not Defined
我试图让图像放大,点击时 float 在屏幕中央,没有jquery,纯javascript,html,css。
HTML
<body>
<script type="text/javascript">
function toggleExpand(id){
var doc = document.getElementById(id);
doc.style.z-index = "1";
doc.style.width = "512px";
doc.style.align = "center";
}
</script>
<img id="img1" onclick="toggleExpand('img1');" src="I:\Images\image.jpg" alt="image" style="width:128px; height:auto; cursor:pointer; z-index:0"/>
</body>
最佳答案
这是我使用的代码,可以使用这个
<html>
<head>
<script>
function toggle(){
var doc = document.getElementById("divSection");
doc.style.z-index = "1";
doc.style.width = "512px";
doc.style.align = "center";
}
</script>
</head>
<body>
<p>Click the button to trigger a function.</p>
<p class="button" onclick="toggle()">Show/hide</p>
</body>
</html>
关于javascript img onclick 函数引用错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35954586/