这是看过孝祥书上的代码后自己写的,可是为什么我按住shift键点击百度图标
仍会触发showSrc()事件呢? 这个例子的意思是当按住shift键后,点击百度图标,就不再显示图片地址了。请大家帮忙看看,我的代码错在什么地方了?我怎么找,也找不出错误。<html>
<head>
<script type="text/javascript">
function showSrc() {
if(window.event.srcElement.tagName == "IMG") {
alert(window.event.srcElement.src);
}
}
function checkCancel() {
if(window.evnent.shiftKey == true) {
window.event.cancelBubble = true;
}
}
</script>
</head><body onclick="showSrc()">
<img src="http://www.baidu.com/img/baidu_logo.gif" onclick="checkCancel()">
</body></html>
仍会触发showSrc()事件呢? 这个例子的意思是当按住shift键后,点击百度图标,就不再显示图片地址了。请大家帮忙看看,我的代码错在什么地方了?我怎么找,也找不出错误。<html>
<head>
<script type="text/javascript">
function showSrc() {
if(window.event.srcElement.tagName == "IMG") {
alert(window.event.srcElement.src);
}
}
function checkCancel() {
if(window.evnent.shiftKey == true) {
window.event.cancelBubble = true;
}
}
</script>
</head><body onclick="showSrc()">
<img src="http://www.baidu.com/img/baidu_logo.gif" onclick="checkCancel()">
</body></html>
这行中 event 写成 evnent了。
改过来就好了。