Knockout to get the Attribute Value onClick function

淺唱寂寞╮ 提交于 2019-12-20 06:29:53

问题


HTML View with attr Value 'Qref'.

This is the HTML Code for bindling

Currently i have hard coded the Qref Attribute vaue

<!--ko if:$parent.Type == 2 -->
<input type="checkbox" data-bind="attr:{id: $data.Id , Qref: '3177'} , click: $root.answerClick">&nbsp;&nbsp;&nbsp;<span data-bind="text: $data.Text , attr:{id: $data.Id}"></span>
<!--ko if:$data.InputType == "text" -->
<input type="text">
<!-- /ko -->
<!-- /ko -->

This is the event for CLick.I am able to access the ID But not able to access the Qref Value.I want to know how can i access the Qref Value.

    answerClick: function (data ,event) {
                    var click_id = event.target.id;
                    return true;
                },

回答1:


You can access attribute values of a DOM using the getAttribute function.

This will work for you:

answerClick: function(c, event){
        var element = event.target;
        var qref = element.getAttribute('Qref');
        var click_id = element.id;
        return true;
    }


来源:https://stackoverflow.com/questions/31513689/knockout-to-get-the-attribute-value-onclick-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!