简体   繁体   English

如何从 Angular 的浏览器控制台中选择选项值?

[英]How to select option value from the browser console in Angular?

How do I select one of the list values from the browser console?如何从浏览器控制台选择列表值之一? Thank you for guiding me谢谢你指导我

<select style="width: 100%" 
        id="Select1" 
        class="css-dropdowns ng-not-empty ng-dirty ng-valid ng-valid-required ng-touched ng-valid-parse"
        name="Select2" 
        ng-model="MP.MP2.MP3ID" 
        required="">
  <option value="" selected="selected">select</option>                           
  <option ng-repeat="o in selectOptions" ng-selected="false" value="1" class="ng-binding ng-scope">
M1
  </option>
  <option ng-repeat="o in " ng-selected="false" value="2" class="ng-binding ng-scope"> M2
  </option>
  <option ng-repeat="o in selectOptions" ng-selected="false" value="3" class="ng-binding ng-scope">                                                       
</select>

Welcome to StackOverflow :)欢迎使用 StackOverflow :)

In order to reach elements from the DOM, you can use the querySelector functionality .为了从 DOM 访问元素,您可以使用querySelector 功能

So to start, you could simply find the element with the id #Select1.因此,首先,您可以简单地找到 ID 为 #Select1 的元素。

let selectElement = document.querySelector('#Select1');

Afterwards you would need to be able to reach the "option" values in the "select" that you reached (I'm leaving this part to you, you can look through the MDN documentation I shared above).之后,您将需要能够到达您到达的“选择”中的“选项”值(我将这部分留给您,您可以查看我上面共享的 MDN 文档)。

In order to mark an option as selected, you can simply say为了将选项标记为已选中,您可以简单地说

option.selected = true;

Hope this helps.希望这可以帮助。 Good luck.祝你好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM