敲除IE浏览器TR标签之间的虚拟元素(Knockout Virtual Elements betwe

2019-07-31 23:12发布

我有以下代码:

...
</tr>
<!-- ko if: eLocBound() == 'true' -->
<tr>
    <td>Select Locations <span class="required_star">*</span></td>
    <td><input type="text" /></td>
</tr>
<!-- /ko -->
<tr>
...

这正确地显示在Chrome / Firefox / Safari。 然而,当我加载页面在IE 9,会出现以下错误:

Cannot find closing comment tag to match: ko if: eLocBound() == 'true'

当我检查在IE浏览器的开发者窗口的HTML输出,我发现IE浏览器实际上是嵌套<!-- ko if -->以前的TR标签 ,而不是在TR标签之间的注释标记,从而击倒无法找到匹配<!-- /ko -->标签。 我已经联系到问题的屏幕截图在这里: http://imgur.com/nN7Ln

相反,如果我的代码改成这样:

<tr data-bind="visible: eLocBound() == 'true'">
    <td>Select Locations <span class="required_star">*</span></td>
    <td><input type="text" /></td>
</tr>

然后一切工作正常。 我只是想知道是否有人遇到这个问题与虚拟元素。

Answer 1:

这是与Internet Explorer中的问题敲除不能真正补偿。 在你的情况,一个好的解决方法是使用一个tbody标签在你行。 一个表可以包括多个tbody标签。 所以,你的代码将如下所示:

 ...
</tr>
<tbody data-bind="if: eLocBound() == 'true'">
<tr>
    <td>Select Locations <span class="required_star">*</span></td>
    <td><input type="text" /></td>
</tr>
</tbody>
<tr>
...


文章来源: Knockout Virtual Elements between TR tags in IE browsers