Jquery 如何根据其他字段值向输入字段添加“必需”属性

Jquery 如何根据其他字段值向输入字段添加“必需”属性,jquery,angularjs,html,Jquery,Angularjs,Html,我有以下输入字段: <input class="text_field" id="ProfilePhoneNumber" phone-by-state="User.PhoneNumber" type="text" required/> <div class="btn-group"> <button multi-select="User.Notifications.Phone" class="btn btn-default dropdown-toggle"&g

我有以下输入字段:

<input class="text_field" id="ProfilePhoneNumber" phone-by-state="User.PhoneNumber" type="text" required/>

<div class="btn-group">
    <button multi-select="User.Notifications.Phone" class="btn btn-default dropdown-toggle">
        Select Severities <span class="caret"></span></button>
    <ul multi-select-dropdown class="dropdown-menu">
        <li>
            <input type="checkbox" id="NotificationsPhone_1"
                   ng-model="User.Notifications.Phone.High">
            <label for="NotificationsPhone_1">High</label>
        </li>
        <li>
            <input type="checkbox" id="NotificationsPhone_2"
                   ng-model="User.Notifications.Phone.Medium">
            <label for="NotificationsPhone_2">Medium</label>
        </li>
        <li>
            <input type="checkbox" id="NotificationsPhone_3"
                   ng-model="User.Notifications.Phone.Low">
            <label for="NotificationsPhone_3">Low</label>
        </li>
    </ul>
</div>

<div><input id="SMS" type="checkbox"
       ng-model="User.SMS.Enabled">SMS Enable
</div>
我想从ProfilePhoneNumber文本字段中删除'required'属性,并且仅当至少选中了这些其他复选框中的一个时才将其设置为必需

我可以通过HTML来做吗?有棱角的jquery? 最好的方法是什么?

您可以在这里使用

如果表达式传递给ng required sets为true,则ng required将在元素上设置required属性。

您可以在此处使用


如果表达式pass to ng required set为true,则ng required将在元素上设置required属性。

您可以使用angularjs ng required

<input class="text_field" id="ProfilePhoneNumber" phone-by-state="User.PhoneNumber" type="text" ng-required="User.Notifications.Phone.High || User.Notifications.Phone.Medium || User.Notifications.Phone.Low"/>

<div class="btn-group">
    <button multi-select="User.Notifications.Phone" class="btn btn-default dropdown-toggle">
        Select Severities <span class="caret"></span></button>
    <ul multi-select-dropdown class="dropdown-menu">
        <li>
            <input type="checkbox" id="NotificationsPhone_1"
                   ng-model="User.Notifications.Phone.High">
            <label for="NotificationsPhone_1">High</label>
        </li>
        <li>
            <input type="checkbox" id="NotificationsPhone_2"
                   ng-model="User.Notifications.Phone.Medium">
            <label for="NotificationsPhone_2">Medium</label>
        </li>
        <li>
            <input type="checkbox" id="NotificationsPhone_3"
                   ng-model="User.Notifications.Phone.Low">
            <label for="NotificationsPhone_3">Low</label>
        </li>
    </ul>
</div>

您可以根据需要使用angularjs ng

<input class="text_field" id="ProfilePhoneNumber" phone-by-state="User.PhoneNumber" type="text" ng-required="User.Notifications.Phone.High || User.Notifications.Phone.Medium || User.Notifications.Phone.Low"/>

<div class="btn-group">
    <button multi-select="User.Notifications.Phone" class="btn btn-default dropdown-toggle">
        Select Severities <span class="caret"></span></button>
    <ul multi-select-dropdown class="dropdown-menu">
        <li>
            <input type="checkbox" id="NotificationsPhone_1"
                   ng-model="User.Notifications.Phone.High">
            <label for="NotificationsPhone_1">High</label>
        </li>
        <li>
            <input type="checkbox" id="NotificationsPhone_2"
                   ng-model="User.Notifications.Phone.Medium">
            <label for="NotificationsPhone_2">Medium</label>
        </li>
        <li>
            <input type="checkbox" id="NotificationsPhone_3"
                   ng-model="User.Notifications.Phone.Low">
            <label for="NotificationsPhone_3">Low</label>
        </li>
    </ul>
</div>
您应该将|运算符更改为| |运算符。角度中的|运算符仅对过滤器有用。应将|更改为| |运算符。角度中的|运算符仅对过滤器有用。