选择值选项

发布于 2025-02-12 09:07:18 字数 4551 浏览 4 评论 0原文

我需要此选择的帮助,我使用此JavaScript代码行,并且它不起作用。

document.getElementById("mySelect").value = "291349";
<select id="mySelect" style="width: 400px; background-color: rgb(235, 245, 251); color: black;" data-select2-id="select2-data-mySelect" tabindex="-1" class="select2-hidden-accessible" aria-hidden="true">
  <option value="97600" data-select2-id="select2-data-12-gt5z">Select White Background Front View Single Rectangular Object /// Angle View Countertop Microwaves // Select White Background Angle View Alcove Bathtubs / TE: 11s</option>
  <option value="251730" data-select2-id="select2-data-13-y5m5">Company Location Validation / TE: 11s</option>
  <option value="500103" data-select2-id="select2-data-14-rp9r">Categories Semantic Similarity V2.1 / TE: 10s</option>
  <option value="700321" data-select2-id="select2-data-15-1adt">Adult Content According To Google Adsense Rules / TE: 12s</option>
  <option value="27319" data-select2-id="select2-data-16-b3ab">Uathans Toxicity Experiment 4/ Uathens Toxicity Definition 6/ Abuse/Offense/Hate/Toxicity Annotation Experiment / TE: 10s</option>
  <option value="303712" data-select2-id="select2-data-17-3itz">Rate Content Of Animated Gifs (Adult Content) V2 / TE: 60s</option>
  <option value="45" data-select2-id="select2-data-18-b2nl">Facebook Page Discovery (En) V2 / TE: 60s</option>
  <option value="103969" data-select2-id="select2-data-19-tp8r">Is This A Sponsored Video? Youtube / TE: 30s</option>
  <option value="829272" data-select2-id="select2-data-20-rjc3">Judging Language Produced By An Artificial Intelligence (C) / TE: 61s</option>
  <option value="848300" data-select2-id="select2-data-21-teec">Find The Official Website Of Businesses JUNIO-22 / TE: 11s</option>
  <option value="902175" data-select2-id="select2-data-22-f1ll">Identify The Bill Of Lading Number (Cf Revision) / TE: 30s</option>
  <option value="291349" data-select2-id="select2-data-23-7edh">Are These Businesses The Same One? / TE: 15s</option>
  <option value="505317" data-select2-id="select2-data-24-e6jm">Find Urls For A Business In A Certain Site / Find Business Urls / TE: 30s</option>
</select>
<span class="select2 select2-container select2-container--bootstrap5 select2-container--focus" dir="ltr" data-select2-id="select2-data-1-qhy7" style="width: 100%;"><span class="selection"><span class="select2-selection select2-selection--single" role="combobox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-disabled="false" aria-labelledby="select2-mySelect-container" aria-controls="select2-mySelect-container"><span class="select2-selection__rendered" id="select2-mySelect-container" role="textbox" aria-readonly="true" title="Select White Background Front View Single Rectangular Object /// Angle View Countertop Microwaves // Select White Background Angle View Alcove Bathtubs / TE: 11s">Select White Background Front View Single Rectangular Object /// Angle View Countertop Microwaves // Select White Background Angle View Alcove Bathtubs / TE: 11s</span>
<span
  class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span>
  </span>
  </span><span class="dropdown-wrapper" aria-hidden="true"></span></span>
  <span class="selection"><span class="select2-selection select2-selection--single" role="combobox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-disabled="false" aria-labelledby="select2-mySelect-container" aria-controls="select2-mySelect-container"><span class="select2-selection__rendered" id="select2-mySelect-container" role="textbox" aria-readonly="true" title="Select White Background Front View Single Rectangular Object /// Angle View Countertop Microwaves // Select White Background Angle View Alcove Bathtubs / TE: 11s">Select White Background Front View Single Rectangular Object /// Angle View Countertop Microwaves // Select White Background Angle View Alcove Bathtubs / TE: 11s</span>
  <span
    class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span>
    </span>
    </span>

我想对JavaScript进行自动选择,但这无效。

I need help for this Select, I use this line of javascript code and it doesn't work.

document.getElementById("mySelect").value = "291349";
<select id="mySelect" style="width: 400px; background-color: rgb(235, 245, 251); color: black;" data-select2-id="select2-data-mySelect" tabindex="-1" class="select2-hidden-accessible" aria-hidden="true">
  <option value="97600" data-select2-id="select2-data-12-gt5z">Select White Background Front View Single Rectangular Object /// Angle View Countertop Microwaves // Select White Background Angle View Alcove Bathtubs / TE: 11s</option>
  <option value="251730" data-select2-id="select2-data-13-y5m5">Company Location Validation / TE: 11s</option>
  <option value="500103" data-select2-id="select2-data-14-rp9r">Categories Semantic Similarity V2.1 / TE: 10s</option>
  <option value="700321" data-select2-id="select2-data-15-1adt">Adult Content According To Google Adsense Rules / TE: 12s</option>
  <option value="27319" data-select2-id="select2-data-16-b3ab">Uathans Toxicity Experiment 4/ Uathens Toxicity Definition 6/ Abuse/Offense/Hate/Toxicity Annotation Experiment / TE: 10s</option>
  <option value="303712" data-select2-id="select2-data-17-3itz">Rate Content Of Animated Gifs (Adult Content) V2 / TE: 60s</option>
  <option value="45" data-select2-id="select2-data-18-b2nl">Facebook Page Discovery (En) V2 / TE: 60s</option>
  <option value="103969" data-select2-id="select2-data-19-tp8r">Is This A Sponsored Video? Youtube / TE: 30s</option>
  <option value="829272" data-select2-id="select2-data-20-rjc3">Judging Language Produced By An Artificial Intelligence (C) / TE: 61s</option>
  <option value="848300" data-select2-id="select2-data-21-teec">Find The Official Website Of Businesses JUNIO-22 / TE: 11s</option>
  <option value="902175" data-select2-id="select2-data-22-f1ll">Identify The Bill Of Lading Number (Cf Revision) / TE: 30s</option>
  <option value="291349" data-select2-id="select2-data-23-7edh">Are These Businesses The Same One? / TE: 15s</option>
  <option value="505317" data-select2-id="select2-data-24-e6jm">Find Urls For A Business In A Certain Site / Find Business Urls / TE: 30s</option>
</select>
<span class="select2 select2-container select2-container--bootstrap5 select2-container--focus" dir="ltr" data-select2-id="select2-data-1-qhy7" style="width: 100%;"><span class="selection"><span class="select2-selection select2-selection--single" role="combobox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-disabled="false" aria-labelledby="select2-mySelect-container" aria-controls="select2-mySelect-container"><span class="select2-selection__rendered" id="select2-mySelect-container" role="textbox" aria-readonly="true" title="Select White Background Front View Single Rectangular Object /// Angle View Countertop Microwaves // Select White Background Angle View Alcove Bathtubs / TE: 11s">Select White Background Front View Single Rectangular Object /// Angle View Countertop Microwaves // Select White Background Angle View Alcove Bathtubs / TE: 11s</span>
<span
  class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span>
  </span>
  </span><span class="dropdown-wrapper" aria-hidden="true"></span></span>
  <span class="selection"><span class="select2-selection select2-selection--single" role="combobox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-disabled="false" aria-labelledby="select2-mySelect-container" aria-controls="select2-mySelect-container"><span class="select2-selection__rendered" id="select2-mySelect-container" role="textbox" aria-readonly="true" title="Select White Background Front View Single Rectangular Object /// Angle View Countertop Microwaves // Select White Background Angle View Alcove Bathtubs / TE: 11s">Select White Background Front View Single Rectangular Object /// Angle View Countertop Microwaves // Select White Background Angle View Alcove Bathtubs / TE: 11s</span>
  <span
    class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span>
    </span>
    </span>

I want to make an automatic selection with javascript but it doesn't work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只有影子陪我不离不弃 2025-02-19 09:07:18

我不知道我是否理解您的问题,但是您是否希望在SELECT中预先选择次要的选项(291349)?如果是这样,我已经测试了您的代码,并且正在工作。如果没有,请进一步澄清。

我复制了您的HTML代码,并将脚本放入单独的文件中。然后,我在HTML中使用脚本调用文件。

I don't know if I understand your question, but do you want the second-to-last option (291349) to be pre-selected in select? If so, I've tested your code and it's working. If not, please clarify further.

I copied your html code and put the script in a separate file. Then I called the file with the script in the html.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文