1

我在 IE8 上遇到了一个非常奇怪的问题(并且仅在低于 8 的 IE 版本上)。问题出在 attr 绑定中,如果我输入编码的电子邮件字符串(使用 %26、%40 等),页面将不会在文本字段中呈现数据绑定(在以下情况下为“firstlast@domain.com”),相反,它将呈现为“mailto:first%26last%40domain.com”。

<a data-bind="    visible: Email.length > 0, text: 'firstlast@domain.com', attr:{ href: 'mailto:' +  'first%26last%40domain.com' }"></a>

奇怪的是,如果我使用非编码字符串,它会呈现得很好

<a data-bind="    visible: Email.length > 0, text: 'firstlast@domain.com', attr:{ href: 'mailto:' +  'first&last@domain.com' }"></a>

这两种方式都可以在 Firefox 和 Chrome 以及更高版本的 IE 上正常工作。

4

1 回答 1

1

我调试了一下,发现 Knockout js 是使用 DOM 方法 setAttribute() 来设置 href。根据 W3School 的文档,setAttribute() 支持浏览器 IE9 和更新版本,所以我认为这就是导致奇怪结果的原因。

我也搜索了关于 setAttribute(),其他人也遇到了类似的问题,请参见下面的链接:

https://social.msdn.microsoft.com/Forums/ie/en-US/aa6bf9a5-0c0b-4a02-a115-c5b85783ca8c/javascript-modifying-href-changes-link-text-as-well-for-mailto-协议?论坛=iewebdevelopment

于 2015-07-30T18:23:27.703 回答