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

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

问题描述

具有attr值"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;
    }

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

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