Angularjs复位输入电台如果连续两次点击 [英] Angularjs reset radio input if clicked twice in a row

查看:135
本文介绍了Angularjs复位输入电台如果连续两次点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下jQuery的点击,我试图angularize与事件的的 NG-点击的却无法真正弄清楚如何。

I have the following jQuery click event that I am trying to "angularize" with an ng-click but can't really figure out how.

$('body').on('click change', 'input[type="radio"]:not([disabled])', function(event) {
    $(this).prop('checked') //if checked
    ? $(this).prop('checked',false).data('waschecked', false)   //uncheck
    : $(this).prop('checked',true).data('waschecked', true);    //else check
});

的目标是检查项目是,事实上,被选择,并且如果这样做,重新设置的单选按钮。

The goal is to check if the item is, indeed, already selected, and if it does, reset the radio button.

任何人都可以点我在正确的方向?

Could anyone point me in the right direction?

推荐答案

在这里,我的建议是使用一个值组状态以及按钮不同的值,并使用 NG-点击的按钮比较组状态。

My suggestion here is to use one value for the group state and a different value for the buttons, and use ng-click to compare the buttons to the group state.

例如:

<input type="radio" ng-checked="true" ng-model="buttons" value="one" ng-click="radioChanged()">
<input type="radio" ng-checked="false" ng-model="buttons" value="two" ng-click="radioChanged()">
<input type="radio" ng-checked="false" ng-model="buttons" value="three" ng-click="radioChanged()">

$scope.radioChanged = function (){
    if ($scope.buttons === $scope.group){
        $scope.buttons = undefined;
    }
    $scope.group = $scope.buttons;
    console.log($scope.group, $scope.buttons);
};

http://plnkr.co/edit/lh9XjWr1cCxdf1asuKxo?p=$p$ PVIEW

这篇关于Angularjs复位输入电台如果连续两次点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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