[英]onclick event doesn't fire in firefox or chrome
I am coding some javascript with jQuery to fire when an img is clicked in my asp.net page. 当我在asp.net页面中单击img时,我正在使用jQuery编码一些JavaScript以触发。
The img is declared as follows: img声明如下:
<img id="zoomIn" alt="Zoom In" src="/Images/Plus.png" onclick="zoomIn();" />
And the .js file function is: .js文件功能是:
function zoomIn() {
zoomLevel += 1;
showMapImage();
}
function showMapImage() {
//show the location map
var img_url = "http://maps.google.com/maps/api/staticmap?center=" + $asp("lblCoordinates").html() + "&size=200x150&sensor=false&zoom=" + zoomLevel + "&markers=color:green%7C" + $asp("lblCoordinates").html();
$("#imgMap").attr('src', img_url);
}
function $asp(serverID) {
return $("[id$='" + serverID + "']");
}
This works fine in IE but not in Chrome or Firefox which makes me think there is something simple wrong somewhere that I can't spot 这在IE中可以正常工作,但在Chrome或Firefox中却不能,这使我认为我无法发现某个地方存在一些简单的错误
由于您已经使用过jQuery,因此您可以使用
$('#zoomIn').click(zoomIn);
You page contain two elements with same name\\id: IMG
HTML element with ID attribute "zoomIn"
and javascript function
with name zoomIn
. 您的页面包含两个具有相同名称\\ id的元素:ID属性为
"zoomIn"
IMG
HTML元素和名称为zoomIn
javascript function
。
Try to rename function zoomIn
or IMG#zoomIn
. 尝试重命名
function zoomIn
或IMG#zoomIn
。
Wrap it inside of an anchor tag and style accordingly. 将其包装在锚定标签内并相应设置样式。
<a href="#" onclick="zoomIn();">
<img id="zoomIn" alt="Zoom In" src="/Images/Plus.png" />
</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.