且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在knockout.js中禁用锚标签

更新时间:2023-11-30 22:54:22

锚定标记无法禁用。最简单的方法是使用 ko绑定,然后渲染 span 而不是

 <! -  ko if:c $ c> anchor  skypeId === null  - > 
< span>无Skype ID< / span>
<! - / ko - >
<! - ko if:skypeId!== null - >
< a id =aQStreamSkypedata-bind =attr:{href:''},点击:$ parent.StoreUserClick,text:skypeId>< / a>
<! - / ko - >

这是一个小提琴


I need to disable the anchor tag inside a foreach loop of knockout.js in HTML.

Here is my code:

<a id="aQStreamSkype" data-bind="attr:{href: ''}, click: $parent.StoreUserClick,disable: ($data.SkypeId == 'null')">Skype </a>

Anchor tags cannot be disabled.
The easiest is to use ko if binding and then render a span instead of the anchor if the skype id is null

<!-- ko if: skypeId === null -->
    <span >No Skype Id</span>
<!-- /ko -->
<!-- ko if: skypeId !== null -->
    <a id="aQStreamSkype" data-bind="attr:{href: ''}, click: $parent.StoreUserClick,text: skypeId"></a>
<!-- /ko -->

Here is a fiddle