js获取select的值实现代码

一款很简单的利用js来获取select当前选中项的值代码,在select有个特别当前值应该是获取它的options的selectedindex的值,这样我们就可以如ojb.options[obj.selectedindex].value来获取了。

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.jzread.com/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>网页特效 获取select的值实现代码</title>
<script language="javascript">
function tttg()
{
 var value =document.myfm.cc.options[document.myfm.cc.selectedindex].value;
 alert(value);
}
</script>
</head>

<body>
<form name="myfm">
    <select name="cc" onchange="tttg();">
        <option value="1">1</option>
        <option value="2">3</option>
        <option value="3">3</option>
        <option value="www.jzread.com">www.jzread.com</option>
        <option value="5">mb.jzread.com</option>
    </select>
</form>
</body>
</html>

时间: 2024-09-18 05:45:28

js获取select的值实现代码的相关文章

javascript 获取select的值实现代码

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.111cn.net/1999/xhtml"> <head> <meta http-equiv="conte

jquery中获取select选中值的代码_jquery

jquery获取select选择的文本与值 获取select 选中的 text : $("#ddlregtype").find("option:selected").text(); 获取select选中的 value: $("#ddlregtype ").val(); 获取select选中的索引: $("#ddlregtype ").get(0).selectedindex;

javascript 获取select下拉列表值的代码_表单特效

比如,在使用DWR的时候,如果你想传递下拉框的参数到后台的话,此时就需要先获取到下拉框的值了. 其实想要获取到下拉框的值是很简单的. 最关键的一段代码就是: 复制代码 代码如下: onchange="show(this.options[this.options.selectedIndex].value);" onchange="show(this.options[this.options.selectedIndex].value);" show是一个自定义的函数名.

JS 获取select(多选下拉)中所选值的示例代码

通过js获取select(多选下拉)中所选值,具体实现如下,有需要的朋友可以参考下,希望对大家有所帮助   复制代码 代码如下: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title> New Document </title> <meta name="Generator" content

js获取select标签的值且兼容IE与firefox

 本篇文章主要介绍了js获取select标签的值且兼容IE与firefox.需要的朋友可以过来参考下,希望对大家有所帮助 jsp代码: 代码如下: <form id="search">  <select id="jobSelect" style="width: 200px;" name="jobSelect">   <s:if test='jobSelect == null || jobSelec

JS获取select的value和text值的简单实例

 本篇文章主要是对JS获取select的value和text值的简单实例进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助 代码如下: <select id = "cityList" >    <select id = "selectId" >       <option value = "0">第0个</option>    </select>      <script&g

js获取select下拉框的值

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-

js获取select(下拉框的值)的值

  <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.111cn.net/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.111cn.net/ 1999/xhtml"> <head> <meta http-equiv="

jquery获取select选中值的方法分析_jquery

本文实例讲述了jquery获取select选中值的方法.分享给大家供大家参考,具体如下: 误区: 以前一直以为jquery获取select中option被选中的文本值,是这样写的: 复制代码 代码如下: $("#s").text(); //获取所有option的文本值 实际上应该这样: 复制代码 代码如下: $("#s option:selected").text(); //获取选中的option的文本值 获取select中option的被选中的value值: $(