单选按钮上需要

时间:2016-09-27 14:31:18

标签: javascript html html5

我正在使用单个html5必需属性作为单选按钮组

<td>
   <label for="input1">English:</label><input type="radio" ng-model="Customer.language" id="input1" required  value="english" />
   <label for="input2">Arabic:</label><input type="radio" ng-model="Customer.language" id="input2"  value="arabic" />
</td>

但它没有按照预期工作 我无法提交结果,直到我选择英语,即使我选择阿拉伯语&#34;在英语&#34;

提示需要的字段消息

2 个答案:

答案 0 :(得分:0)

您需要为单选按钮组添加名称属性:

<input type="radio" ng-model="Customer.language" id="input1"  value="english" name="language" required />
<input type="radio" ng-model="Customer.language" id="input2"  value="arabic"  name="language" required />

注意:我也为第二个输入添加了必需的语句。

答案 1 :(得分:0)

我在你的组件中看到一些“ng-”,所以我认为你使用AngularJS。 因此,您可以根据需要尝试这个:

<td>
  <label for="input1">English:</label><input type="radio" ng-model="Customer.language" id="input1" ng-required="!Customer.language"  value="english" />
  <label for="input2">Arabic:</label><input type="radio" ng-model="Customer.language" id="input2" ng-required="!Customer.language" value="arabic" />

不需要名字;)     

这样,只有在没有选择任何值时才需要您的字段;)