简单描述:后台需要获取到select标签选择的内容,也就是text,该怎么取呢?很简单. 代码: //hml代码<div class="col-md-6"> <label class="control-label flex" style="margin-top: 10px;"> 机构<span class="star align-items">*</span> </labe…
js函数方法: <script> function getDefaultSelectedOption(selectId, valIfNull) { var selectId = selectId.replace(/^#/, ''), opts; try { opts = document.getElementById(selectId).getElementsByTagName('option'); for (var i in opts) { if (opts[i].defaultSelect…
一:JavaScript原生的方法 1:拿到select对象: var myselect=document.getElementById(“test”); 2:拿到选中项的索引:var index=myselect.selectedIndex ; // selectedIndex代表的是你所选中项的index 3:拿到选中项options的value: myselect.options[index].value; 4:拿到选中项options的text: myselect.options[ind…
很简单的select标签: <select id="hello" onchange="getContent(this.value,this.options[this.selectedIndex].text)"><option value=1>a</option><option value=2>b</option><option value=3>c</option><option…
<select id="select">      <option>绥江</option>      <option>西江</option>      <option>北江</option>      <option>贺江</option>      <option>新兴江</option> </select> $(function(){  …
本来天真的以为直接this.value()就能去到select的值,可事实并非那么回事. <script> document.getElementById('select').onchange=function(){ console.log(this.value) // return ''; } </script> this是select下拉框对象,是一个集合,so,打印出this.options来看看 good,找到了,selectedIndex,就是这货,选中的值的索引 ok,…
关键代码如下: form.on('select(groupCode)', function(data){ console.log($(data.elem).find("option:selected").attr("title")); }); 相关代码: SELECT渲染如下 <select name="groupCode" lay-search lay-filter="groupCode"> <option…
$("#magSeaTypeSelect option:selected").text();…
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><h…
Js获取select下拉列表框各个Option的Value值相对比较容易,不过获取Text值却有点麻烦,对于一个初学JavaScript的 新手来说,可能一时还无从下手,那么就请看下本文的方法,以一个form表单中的Select下拉框菜单为例,来说明如何用JavaScript获取其 Value值和Text值: 示例表单,里面是一个select下拉列表框的各个列表项及值: <form name="form1"> <select name="testvalue&…