我在 Asp.Net 用户控件中有一个 anchor 。我已将一些代码连接到 onclick 事件。由于某些原因,在 Internet Explorer 10 中,该事件未触发。标记的结构为
<a href="#" id="myAnchor" onclick="myFunction();return false;"></a>
其中 myFunction 是一个简单的 JavaScript 函数。对于那些想要查看该页面实际运行情况的人,请点击以下链接:
http://alt.thedominion.ca/TheBrokerAdvantage/LocateABroker.aspx
非常感谢任何帮助!
最佳答案
问题出在服务器端代码,而不是浏览器或 JavaScript。
如果您检查 IE10 中的 JavaScript 控制台,单击链接时您将看到以下错误:
SCRIPT5009: 'ValidatorValidate' is undefined
指向函数中的第二行:
function doSearch() {
var regExValidate = document.getElementById("ctl00_BrokerSearchMiddle_ctl00_ValidPostalCode");
ValidatorValidate(regExValidate);
var postalCode = $find("ctl00_BrokerSearchMiddle_ctl00_PostalCode").get_value();
if (regExValidate.isvalid && postalCode.indexOf("e.g") == -1) {
document.location.href = "?postalCode=" + postalCode;
}
}
这意味着 onclick
工作正常,只是有 JS 错误。
现在的问题是为什么 ValidatorValidate
在其他浏览器(甚至IE9)中存在,但在IE10中不存在。嗯,在 IE10 中the script where it's being defined不包括在内,这意味着服务器永远不会放置 <script src="...">
行将该 URL 作为浏览器输出的一部分。
我只能猜测服务器端代码正在检查浏览器版本并根据该版本包含某些脚本。检查该代码并删除此类内容,因为这从来都不是一个好主意。
经过一番研究,我发现发生了什么事。您正在使用 Sitefinity 版本 3.7 来构建您的网站(根据 this question of yours )以及官方 stated here :
I want to inform you that unfortunately Sitefinity 3.7 does not support Internet Explorer 10 and your Sitefinity 3.7 might not work properly with this browser version. Apologies for the inconvenience
如果您需要 IE10 支持,则必须升级 Sitefinity。
关于javascript - anchor 标记中的 Onclick 事件在 IE10 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16149131/