![](/img/trans.png)
[英]When using PHP to save a drop down menu selection it remembers the selection but doesnt trigger the onchange event changing the CSS when reloaded
[英]drop down menu selection using console doesn't trigger event
我想在控制台的幫助下為字段設置值,但是當我這樣做時,它不會觸發當我從下拉列表中選擇選項時應該發生的事件。它僅在下拉菜單字段中顯示所選值,但事件不會不會發生。
我在控制台上使用以下查詢:
document.getElementsByClassName("input-text")[5].value="string:100#2#######"
以下是HTML選擇的代碼:-
<select class="input-text ng-pristine ng-valid ng-touched" ng-model="selectedSname" ng-show="snames != null && (name712 != null && name712 != '')" ng-options="sname.surveypins as sname.fullname for sname in snames">
<option selected="selected"></option>
<option label="1" value="string:55#9####### ">abc</option>
<option label="2" value="string:100#2####### ">xyz</option>
</select>
您必須手動調用onchange
方法,例如:
HTML:
<select id="test">
<option value="1">1</option>
<option value="2">2</option>
</select>
JS:
document.getElementById('test').onchange = function () {
alert('changed');
}
document.getElementById('test').value = "2";
document.getElementById('test').onchange();
工作正常的JSFiddle在這里
並且因為您使用的是AngularJS,所以我們必須通過如下所示的角度方式選擇選項:
$scope.selectedSname = "string:100#2#######";
因此,角度將捕獲您的更改並觸發摘要循環,這將觸發更改事件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.