gpt4 book ai didi

javascript - ng-change 事件不适用于下拉菜单

转载 作者:行者123 更新时间:2023-11-29 19:13:09 25 4
gpt4 key购买 nike

我正在创建一个下拉菜单,其中包含员工和客户两个选项,如果它是用户,那么应该打开一个新的文本框,即员工 ID,如果是客户,则文本框应该隐藏。我正在使用 Angular JS 这是我的 HTML 文件。

下拉代码

<div class="row control-group">
<label class="col-xs-4 col-sm-4 col-md-3 col-lg-3 control-label">{{::'label.identity'|translate}}</label>
<div class="col-xs-7 col-sm-7 col-md-9 col-lg-9 controls">
<select id="selectIdentity" name="selectIdentity">
<!-- Empty option necessary for placeholder to work -->
<option value="">{{::'define.selectval'|translate}}</option>
<option ng-repeat="idprovider in identityProvider" ui-select2="select2IdentityProvider" class="selectIdentity" ng-model="identityprovider" ng-change="changedValue(identityprovider)" ui-select2="select2LocaleSettings">{{idprovider}}</option>
</select>
<span class="help-block" ng-show="addUserForm.selectIdentity.$error.required">{{::'error.required'|translate}}</span>
</div>
</div>

文本框代码

        <div class="row control-group" ng-show="identityprovider == EMPLOYEE"
ng-class="{error:addUserForm.sso.$dirty && !addUserForm.sso.$valid , success:addUserForm.sso.$valid}">
<label class="col-xs-4 col-sm-4 col-md-3 col-lg-3 control-label">{{::'label.addUser.SSO'|translate}}</label>

<div class="col-xs-7 col-sm-7 col-md-9 col-lg-9 controls">
<input type="text" class="input-xlarge" id="sso" name="sso"
ng-model="addUser.user.sso" ng-pattern="ssoPattern"
placeholder="{{::'placeholder.addUser.sso'|translate}}"
ng-change="addUserForm.sso.$setValidity('duplicateName', true);"
required="true" ng-maxlength=8 ng-minlength=8 ge-auto-focus />

<span class="help-block"
ng-show="addUserForm.sso.$dirty && addUserForm.sso.$error.required">{{::'error.required'|translate}}</span>
<span class="help-block"
ng-show="addUserForm.sso.$dirty && addUserForm.sso.$error.pattern">{{::'error.sso'|translate}}</span>



<span class="help-block"
ng-show="addUserForm.sso.$dirty && addUserForm.sso.$error.maxlength">{{::'error.max.length'|translate}}</span>
<span class="help-block"
ng-show="addUserForm.sso.$dirty && addUserForm.sso.$error.duplicateName">{{::'error.editOrganization.duplicateName'|translate}}</span>
</div>
</div>

JS 文件数据

    $scope.identityProvider=['EMPLOYEE','Customer'];

$scope.changedValue = function(item) {
alert("M into change");
$scope.itemList.push(item.name);
}

最佳答案

select标签中添加ng-change,

<select id="selectIdentity" name="selectIdentity" ng-change="changedValue(identityprovider)" ng-model="identityprovider" required>
</select>

关于javascript - ng-change 事件不适用于下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37321952/

25 4 0