如何设置单选按钮的属性以选中

时间:2018-06-08 07:25:50

标签: javascript angularjs

我的代码中有两个单选按钮:

<input type="radio" id='production' ng-click="division($event)" ng-model="formData.division" value="Production">
  <label for="production">Production</label>

<input type="radio" id='operation' ng-click="division($event)" ng-model="formData.division" value="Operations">
  <label for="operation">Operations</label>

还有更多单选按钮:

<div class="prod">
  <h2>Production</h2>
    <label><b>Project Captain: <small id="small">*</small></b></label>
    <input type="radio" class="projCap" ng-model="formData.projCap" value="yes">Yes
    <input type="radio" class="projCap" ng-model="formData.projCap" value="no">No

    <label><b>Supervisor: <small id="small">*</small></b></label>
    <input type="radio" ng-model="formData.supervisor" value="yes">Yes
    <input type="radio" ng-model="formData.supervisor" value="no">No<br><br>
</div>

<div class="op">
  <h2>Operations</h2>
    <label><b>Manager: <small id="small">*</small></b></label>
    <input type="radio" ng-model="formData.mngr" value="yes">Yes
    <input type="radio" ng-model="formData.mngr" value="no">No   

    <label><b>Assistant Manager: <small id="small">*</small></b></label>
    <input type="radio" ng-model="formData.asMngr" value="yes">Yes
    <input type="radio" ng-model="formData.asMngr" value="no">No  <br><br>
</div>

我想为用户节省时间,例如,如果用户选择Production,则应自动将所有单选按钮设置为div no内的op。 如果在Operations内选择no值为prod的所有单选按钮,则$scope.division = function(event) { if(event.target.id === 'production'){ $('.op').find('input:radio').prop('checked', true); $('.prod').find('input:radio').prop('checked', false); }else{ $('.prod').find('input:radio').prop('checked', true); $('.op').find('input:radio').prop('checked', false); } };

我在控制器中的功能:

yes

它会同时选择nono值: enter image description here

如何仅自动选择create: (req, res) => { let deleteRows = (rows) => { rows.forEach((row) => { console.log("============="); console.log(row); console.log("============="); models.TABLE.destroy({ where: {CNTRY_CD: row['CNTRY_CD'], AREA_ID: row['AREA_ID'], BUS_DT: row['BUS_DT']}}) .then((region, err) => { if(err) { console.log("I am here"); return res.status(500).json({ error: 'Internal Server Error' }); } //res.status(200).json(region); }); }); }; deleteRows(req.body.rows) .then((err) => { if(err) { console.log("Instead I am here"); return res.status(500).json({ err: 'Internal Server Error' }); } else { models.TABLE.bulkCreate(req.body.rows) .then((rows, err) => { if(err) { return res.status(500).json({ err: 'Internal Server Error' }); } else { return res.status(201).json(`${req.body.rows.length} rows successfully inserted!`); } }) .catch((err) => { res.status(500).json(err); }); } }); } 值的单选按钮?

1 个答案:

答案 0 :(得分:3)

试试这个:

$('.op').find('input:radio[value="no"]').prop('checked', true);

并且不要忘记为群组中的所有广播提供相同的名称,否则它们将作为复选框。

检查此示例:

&#13;
&#13;
$(document).ready(function(){
  $('.op').find('input:radio[value="no"]').prop('checked', true);
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="op">
  <h2>Operations</h2>
    <label><b>Manager: <small id="small">*</small></b></label>
    <input type="radio" name="group1" ng-model="formData.mngr" value="yes">Yes
    <input type="radio" name="group1" ng-model="formData.mngr" value="no">No   

    <label><b>Assistant Manager: <small id="small">*</small></b></label>
    <input type="radio" name="group2" ng-model="formData.asMngr" value="yes">Yes
    <input type="radio" name="group2" ng-model="formData.asMngr" value="no">No  <br><br>
</div>
&#13;
&#13;
&#13;