Knockout 获取属性值 onClick 函数 [英] Knockout to get the Attribute Value onClick function

查看:20
本文介绍了Knockout 获取属性值 onClick 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

带有属性值Qref"的 HTML 视图.

HTML View with attr Value 'Qref'.

这是绑定的 HTML 代码

This is the HTML Code for bindling

目前我已经硬编码了 Qref 属性值

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 -->

这是 CLick 的事件.我可以访问 ID 但无法访问 Qref 值.我想知道如何访问 Qref 值.

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;
                },

推荐答案

您可以使用 getAttribute 函数.

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

这对你有用:

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

这篇关于Knockout 获取属性值 onClick 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆