从两个不同的字段中获取一个值(无线电,数字)

时间:2016-12-30 19:23:16

标签: javascript jquery angularjs html-form

我正在寻找从此图片中找到的表单收集输入:

freelancer question, radio button and text box

就像UpWork一样,我想从两个不同的领域中获取一个值。

我试过了:

<div class="col-md-6">
    <label for="PostForm_freelancersToHire" class="required">How many freelancers do you need for this job?</label>
    <div class="row">
        <div class="col-md-12">
            <div class="radio">
                <label>
                    <input type="radio" data-ng-click="setManyFreelancers(false)" name="hMoreF"  ng-model="oneFreelancer" checked="checked" />
                    <span class=""></span>
                    I want to hire one freelancer
                </label>
            </div>
            <div class="radio">
                <label>
                    <input type="radio" data-ng-click="setManyFreelancers(true)" name="hMoreF"  />
                    <span class=""></span>
                    I need to hire more than one freelancer
                </label>
            </div><!---->
        </div>
    </div>

    <div class="row" ng-if="hasManyFreelancers">
        <div class="col-xs-4">
            <input type="number" name="oneMoreFreelancer" ng-model="oneMoreFreelancer" min="2" class="form-control" />
        </div>
        <div class="col-xs-3" style="padding:5px 0 0">
            <span>Freelancers</span>
        </div>
    </div>
</div>

Angular JS:

$scope.setManyFreelancers = function (t) {
    if (t) {
        $scope.hasManyFreelancers = true;
    }
    else {
        $scope.hasManyFreelancers = false;
        // $scope.oneMoreFreelancer = '';
    }
}

$scope.oneMoreFreelancer$scope.oneFreelancer都是undefined

如果选择了第一台收音机,我会喜欢它的价值。如果选择了第二个收音机,我喜欢数字输入值。我该如何正确地获取它?

0 个答案:

没有答案