ng-click for checkbox不能正常加载,它在页面刷新时工作?

时间:2017-01-16 13:48:35

标签: javascript jquery html angularjs checkbox

Checkbox无法加载文件,但是在页面刷新后工作

我的template

<div class="checkbox">
    <label>
        <input type="checkbox" id="farmCat" class="farmCatCrop" ng-click="valueChangedTwo()"> Crop </label>
    <label>
        <input type="checkbox" id="farmLive" class="farmCatLiveStock" ng-click="valueChangedTwo()"> Live Stock </label>
</div>
现金 家畜

我的method

$scope.valueChangedTwo = function() {
    if ($('.farmCatCrop').is(":checked"))
        $("#cash").show();
    else
        $("#cash").hide();

    if ($('.farmCatLiveStock').is(":checked"))
        $("#liveField").show();
    else
        $("#liveField").hide();
};

1 个答案:

答案 0 :(得分:0)

<div class="checkbox">
<label>
<input type="checkbox" id="farmCat" class="farmCatCrop" ng-model="cat.crop">Crop </label>
<label>
<input type="checkbox" id="farmLive" class="farmCatLiveStock" ng-model="cat.livestock">Live Stock </label>
</div>

然后......

<div id="cash" ng-show="cat.crop">Cash</div>
<div id="liveField" ng-show="cat.livestock">Live Stock</div>

你不会需要jQuery,因为angularjs可以做得更好。