【问题标题】:In the multiple choice checkbox, I want a single value to be selected when the page is first opened. I couldn't. How can I?在多选复选框中,我希望在首次打开页面时选择一个值。我不能。我怎样才能?
【发布时间】:2021-11-24 20:38:45
【问题描述】:

在多选字段中,我希望在第一次打开页面时立即选择该值。我在这方面经验不足。我做不到。如果您能提供帮助,我会很高兴。

.cshtml代码:

<div style="margin:5px 0;"></div>
                <a class="btn btn-default" style="width:100%" ng-show="queryRayonIdBool" ng-click="showRayon()">Choose department...<span class="glyphicon glyphicon-chevron-down pull-right"></span></a>
                <div class="listbutton" ng-show="ShowRayon">
                    <div class="listbox" data-offset-top="50">
                        <a class="btn btn-default allselectbutton" ng-click="checkrayon()">Select All</a>
                        <a class="btn btn-default allselectbutton" ng-click="checkrayonnot()">Remove All</a>
                    </div>
                    <div style="padding-top:20px;">
                        <div style="float:none;" ng-repeat="ray in rayons">
                            <label class="checkbox-inline">
                                <input ng-model="ray.checked2" type="checkbox" value="{{ray.Id}}" ng-click='Checked2(ray)' /><p>{{ray.title}}</p>
                            </label>
                        </div>
                    </div>
                </div>

.js 代码:

$scope.Checkedval2 = "";
$scope.CheckedId2 = "";
$scope.checkrayon = function () {
    $scope.CheckedId2 = "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22";
    angular.forEach($scope.rayons, function (value, key) {
        value.checked2 = true;

    });
}


rayondata = [];
rayondata.push({ 'id': 0, 'title': "Choose Department... (All Departments)" });
arkadashttp.get(arkadasservice.appOrigin + "/api/RayonApi/GetList",
{})
.then(function (rdata, status) {

    angular.forEach(rdata, function (item) {
        rayondata.push({ 'id': item.Id, 'title': item.RayonName });

    });
});

$scope.ProcessedNames = rayondata;
$rootScope.rayons = rayondata;
$scope.showRayon = function () {
    $scope.ShowRayon = !$scope.ShowRayon;

}

如何进行更改,以便在第一次打开页面时选择我想要的值?非常感谢您。

【问题讨论】:

    标签: javascript c# html angularjs


    【解决方案1】:

    您应该能够将选中的元素添加到元素中。这应该在页面加载时默认选择它。

    <input ng-model="ray.checked2" type="checkbox" value="{{ray.Id}}" ng-click='Checked2(ray)' checked />
    

    【讨论】:

    • 我试过 ng-checked。它可以被赋予一个真或假的值。在 True 中,所有这些都被选中,我无法删除我想要的选择。所以不幸的是它没有工作,非常感谢你
    猜你喜欢
    • 2021-11-08
    • 1970-01-01
    • 2016-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多