【问题标题】:IE8 Label for and Knockout bindingIE8 标签和敲除绑定
【发布时间】:2015-04-09 06:38:31
【问题描述】:

我有一个带有复选框和标签的模板,它与剔除“for”属性绑定。

无法触发点击事件,但在IE8以外的所有浏览器都可以使用

 <input class="checkbox" type="checkbox" data-bind="value:Id,checked:$root.selectedCategoryIds,attr: { 'id': 'product-choice-' + Id, name: Name }" />
 <label class="label-container" data-bind="attr: { 'for': IsEnabled ? 'product-choice-' + Id : '' }">                
            <span class="checkbox-icon" data-bind="visible:IsEnabled"></span>
            <span class="checkbox-label" data-bind="text:Name"></span>
 </label>

即使我已经指定了文档标准。

有什么解决办法

【问题讨论】:

标签: javascript jquery knockout.js internet-explorer-8


【解决方案1】:

当不带引号的属性同时也是 javascript 中的保留字(如 forclass)在 HTML 中时(我使用 class)时,IE8 有时会引发错误。因此,在data-bind 中引用您的属性是最安全的,例如:data-bind="attr: { 'for': 'mylabel, 'class': 'myclass' }"。确保在标签上同时使用 for 并在输入上使用 nameid

另外,当你在表达式中使用 observable(如果你这样做的话)(在上面的示例中为isEnabled),你应该执行它:isEnabled(),否则它总是会返回 true。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-27
    • 2015-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-13
    相关资源
    最近更新 更多