欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

获取select中option的值或文本

程序员文章站 2022-06-23 10:37:46
获取select中option的值或文本。1.selectedIndex指的是当前被选中的文本的索引值。2.节点.options[节点.selectedIndex]是指定的某个标签3.节点.options[节点.selectedIndex].value获取或设置所选中的列表值。节点.options[节点.selectedIndex].text获取或修改所选中的列表文本内容。文...</div> <div class="content"> <h2> <a id="selectoption_0" target="_blank" rel="nofollow" href="/default/index/url?u=aHR0cHM6Ly93d3cuMTBxaWFud2FuLmNvbQ=="></a>获取select中option的值或文本。</h2> <hr> <p>1.selectedIndex指的是当前被选中的文本的索引值。<br> 2.节点.options[节点.selectedIndex]是指定的某个标签<br> 3.节点.options[节点.selectedIndex].value获取或设置所选中的列表值。<br> 节点.options[节点.selectedIndex].text获取或修改所选中的列表文本内容。</p> <pre><code class="prism language-html"><span class="token doctype"><!DOCTYPE html></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>html</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>head</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>title</span><span class="token punctuation">></span></span>文档标题<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>title</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>head</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>body</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>select</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>lie<span class="token punctuation">"</span></span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>option</span><span class="token punctuation">></span></span>值<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>option</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>option</span> <span class="token attr-name">selected</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>selected<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>递减<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>递增<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>option</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>option</span><span class="token punctuation">></span></span>类<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>option</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>option</span><span class="token punctuation">></span></span>属性<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>option</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>select</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>body</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>script</span><span class="token punctuation">></span></span><span class="token script language-javascript"> <span class="token keyword">var</span> lie<span class="token operator">=</span>document<span class="token punctuation">.</span><span class="token function">getElementById</span><span class="token punctuation">(</span><span class="token string">"lie"</span><span class="token punctuation">)</span><span class="token comment">//获取select标签</span> <span class="token keyword">var</span> index<span class="token operator">=</span>lie<span class="token punctuation">.</span>selectedIndex<span class="token comment">//获取选中的option的角标</span> <span class="token keyword">var</span> value<span class="token operator">=</span>lie<span class="token punctuation">.</span>options<span class="token punctuation">[</span>index<span class="token punctuation">]</span><span class="token punctuation">.</span>value<span class="token comment">//获取option的值</span> <span class="token keyword">var</span> text<span class="token operator">=</span>lie<span class="token punctuation">.</span>options<span class="token punctuation">[</span>index<span class="token punctuation">]</span><span class="token punctuation">.</span>text<span class="token comment">//获取option的文本内容</span> document<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span>value<span class="token punctuation">)</span> doucment<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span>text<span class="token punctuation">)</span> </span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>script</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>html</span><span class="token punctuation">></span></span> </code></pre> <p>网页展示内容(电脑宕机了????)</p> <p><img onerror="this.src='/statics/superweb999/images/image_error.jpg'"src="/default/index/img?u=aHR0cDovL2ltYWdlczUuMTBxaWFud2FuLmNvbS8xMHFpYW53YW4vMjAyMDEyMTQvYl8wXzIwMjAxMjE0MTg1OTI1NDgxOS5qcGc=" alt="获取select中option的值或文本" title="获取select中option的值或文本"></p> <p>本文地址:https://blog.csdn.net/qq_43445758/article/details/111123931</p> </div> <div class="tags"> 相关标签: <a href="/t/%E7%AC%94%E8%AE%B0/" target="_blank"> 笔记 </a> </div> <div class="info-pre-next"> <p> 上一篇: <a href="/article/1500722.html"> Android中在WebView里实现Javascript调用Java类的方法 </a> </p> <p> 下一篇: <a href="/article/1500724.html"> 一万元启动资金,现在可以运营哪些有前景的创业项目?推荐几个 </a> </p> </div> <div class="wz_tuijian"> <p> 推荐阅读 </p> <ul> <li> <a href="/article/1941457.html" target="_blank" title="js获取select下拉框的value值和text文本值"> <h2> js获取select下拉框的value值和text文本值 </h2> </a> </li> <li> <a href="/article/1915150.html" target="_blank" title="用jquery获取select标签中选中的option值及文本的示例"> <h2> 用jquery获取select标签中选中的option值及文本的示例 </h2> </a> </li> <li> <a href="/article/1841043.html" target="_blank" title="JavaScript实现获取select下拉框中第一个值的方法"> <h2> JavaScript实现获取select下拉框中第一个值的方法 </h2> </a> </li> <li> <a href="/article/1782011.html" target="_blank" title="JavaScript获取select中text值的方法"> <h2> JavaScript获取select中text值的方法 </h2> </a> </li> <li> <a href="/article/1781381.html" target="_blank" title="jquery获取select选中的文本值"> <h2> jquery获取select选中的文本值 </h2> </a> </li> <li> <a href="/article/1738028.html" target="_blank" title="jQuery - 实现获取select下拉框选项的改变触发的onchange事件选择的option值"> <h2> jQuery - 实现获取select下拉框选项的改变触发的onchange事件选择的option值 </h2> </a> </li> <li> <a href="/article/1710341.html" target="_blank" title="记录自己不会的地方---webform中基于表格的基础上获取其中文本框的值"> <h2> 记录自己不会的地方---webform中基于表格的基础上获取其中文本框的值 </h2> </a> </li> <li> <a href="/article/1522771.html" target="_blank" title="在Vue 中获取下拉框的文本及选项值操作"> <h2> 在Vue 中获取下拉框的文本及选项值操作 </h2> </a> </li> <li> <a href="/article/1500723.html" target="_blank" title="获取select中option的值或文本"> <h2> 获取select中option的值或文本 </h2> </a> </li> <li> <a href="/article/1462063.html" target="_blank" title="uniapp获取input文本框中的值"> <h2> uniapp获取input文本框中的值 </h2> </a> </li> </ul> </div> </article> </div> </main> <footer><div class="box"><div class="ft_nav"><div class="ft_about"><p>关于网站</p><ul><li><a href="/sitemap.xml" target="_blank" title="网站地图">网站地图</a></li><li><a href="/list/2/" title="最新程序员文章站">最新程序员文章站</a></li></ul></div><div class="ft_contact"><ul><li>本站所有数据收集于网络如有侵犯到您的权益,请联系我们进行下架处理。</li><li class="email_show"></li></ul></div></div><div class="copyright"><div class="cr_left"><p> 备案号:<a href="https://beian.miit.gov.cn/#/Integrated/index" target="_blank">粤ICP备20058927号</a></p><p>© Copyright © 2020-2022 www.superweb999.com 程序员文章站. </p></div></div></div></footer> </body> </html>