select下拉列表!使其不可改变!并且可以得到默认值 用JS代码disabled不行啊!用disabled获得不到默认值求解答啊!项目赶时间啊! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <script>function foo(obj){ obj.selectedIndex=0;}</script><form action='f.php' method='post'><select name='key' id='key' onchange='foo(this)'><option value=0>All</option><option value=1>aa</option><option value=2>bb</option><option value=3>cc</option></select><input type='submit'></form>或者就用disabled禁用掉,将select框的默认值放入一个隐藏域中,再提交。 这个是 onchange事件后还原的不是初始值啊!而是默认值啊!!!!! 既然不让选中,又有默认值,用input标签不行吗 如果要让它不可选,只能用DISABLE,把值赋值给一个隐藏域再取值吧 <select name='key' id='key' disabled="disabled"> <option value=0>All</option> <option value=1>aa</option> <option value="2" selected="selected">bb</option> <option value=3>cc</option> </select> <script type="text/javascript">alert(document.getElementById('key').value)</script>这样会取不到值???? 我就是想让下拉列表除了默认值以外 其他的选项不显示!不能用disabled 我在9楼写的,不就是:使其不可改变,并且可以得到默认值。再加上上面说的什么“其他的选项不显示”其他的用了disabled,其他的本来就看不到了呀表示不明白你想表达的意思 仿一个select,另一个hidden来存这个值 一页面只显示默认值的select,在后台输出时,都只输出默认项,其它的不输出二页面select 设置disabled,另生成一个关联的hidden,设置值为默认值三绑定onchange,onfocus事件, 不得焦点,不响应change事件 <!DOCTYPE html><html><head> <title></title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js" type="text/javascript"></script> <script type="text/javascript"> function getValue(){ alert("第1个select的值:"+document.getElementById('select1').value); alert("第2个select的值:"+document.getElementById('select2').value); } </script></head><body><div> <div style="border:solid 1px green;" > 第1种:按原意,不过客户可能还是会有点误会的(能够动,为什么修改不了?)<br /> <select id="select1" onfocus="this.defaultIndex=this.selectedIndex;" onchange="this.selectedIndex=this.defaultIndex;"> <option value="1">test1</option> <option value="2">test2</option> <option value="3" selected="selected">test3</option> <option value="4">test4</option> <option value="5">test5</option> </select> </div> <div style="border:solid 1px red;" > 第2种:在加载完span和select时,将select2的值给span<br /> <span id="spanSelect2" ></span> <select id="select2" style="display:none;" > <option value="1">test1</option> <option value="2">test2</option> <option value="3" selected="selected">test3</option> <option value="4">test4</option> <option value="5">test5</option> </select> <script type="text/javascript"> //在加载完span和select时,将select2的值给span var select2 = document.getElementById("select2"); var txt = select2.options[select2.selectedIndex].text; document.getElementById("spanSelect2").innerHTML = txt; </script> </div> <input type="button" onclick="getValue()" value="取得值" /></div></body></html>两种方法,看着办吧。 用个浮动层盖住select不给操作就行了<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><span style="position:relative"><select><option value="1">1</option><option value="2">2</option><option value="3">3</option></select><div style="position:absolute;width:100%;height:100%;left:0px;top:0px;background:#fff;opacity:0;filter:alpha(opacity=0)"> </div></span> 我的意思是 单击下拉列表时 没有其他的option 只有一个默认的!我页面全都是用readonly 你一个下拉列表编程 disabled能好看么!?????还有 页面原有的readonly不能改变样子!所以我说不能用disabled <html><body><select > <option>1</option> <option selected>2</option> <option>3</option> <option>4</option> <option>5</option> </select> </bodu></html>只显示2 并且不可点击1 3 4 5 如何绑定onchange,onfocus事件,不得焦点,不响应change事件 修改DOM结构行不行。给select分配个ID,根据其它界面传来的值在body onLoad事件时动态Remove select的Child,然后把仅剩的Child设定selected属性,这样用户页面的下拉框里就只有一个值了。 不明白楼主为什么不愿意看17楼. 17楼与15楼相结合,就是非常完美的了。下面的代码,在17楼加上了一个 onfocus="this.blur();", 防止客户用键盘来修改值。<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><span style="position:relative"><select onfocus="this.blur();"><option value="1">1</option><option value="2">2</option><option value="3">3</option></select><div style="position:absolute;width:100%;height:100%;left:0px;top:0px;background:#fff;opacity:0;filter:alpha(opacity=0)"> </div></span> 默认值又不会变,你预先存起来就好了。然后弄一个只有一个<option>的<select>就好了啊,不明白楼主为什么这么纠结。 disabled可以,不过得把select的值放到隐藏表单里面 禁用了。用户看着不能选。忽悠用户啊?既然不能先,是定值。为什么不用 span input 这些标签 变态的需求!<html><body><select > <option disabled>1</option> <option selected>2</option> <option disabled>3</option> <option disabled>4</option> <option disabled>5</option> </select> </body></html> 在Action里面获取会报空指针异常 如何实现页面自动滚动 在js中,对象和hasttable有什么差别呀 如何让网页打开时候最小化,6秒后最大化 关于恒星的三级联动,有问题要问? 一段去除字符串左右两边空格的代码,不懂,请教当中。 一个简单的窗口鼠标事件问题~~快来了? 如何使层位于flash之上? 请问怎么理解 container的概念 如何屏蔽掉F12下面的那个键<- html文件引入另一个html头文件,造成js失效,请教 fancybox提交表单 JQuery 同样的代码为何部署为网站就显示圆角无效呢?
function foo(obj){
obj.selectedIndex=0;
}
</script>
<form action='f.php' method='post'>
<select name='key' id='key' onchange='foo(this)'>
<option value=0>All</option>
<option value=1>aa</option>
<option value=2>bb</option>
<option value=3>cc</option>
</select>
<input type='submit'>
</form>
或者就用disabled禁用掉,将select框的默认值放入一个隐藏域中,再提交。
<option value=0>All</option>
<option value=1>aa</option>
<option value="2" selected="selected">bb</option>
<option value=3>cc</option>
</select>
<script type="text/javascript">
alert(document.getElementById('key').value)
</script>这样会取不到值????
页面只显示默认值的select,在后台输出时,都只输出默认项,其它的不输出二
页面select 设置disabled,另生成一个关联的hidden,设置值为默认值三
绑定onchange,onfocus事件, 不得焦点,不响应change事件
<html>
<head>
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
function getValue(){
alert("第1个select的值:"+document.getElementById('select1').value);
alert("第2个select的值:"+document.getElementById('select2').value);
}
</script>
</head>
<body>
<div>
<div style="border:solid 1px green;" >
第1种:按原意,不过客户可能还是会有点误会的(能够动,为什么修改不了?)<br />
<select id="select1" onfocus="this.defaultIndex=this.selectedIndex;" onchange="this.selectedIndex=this.defaultIndex;">
<option value="1">test1</option>
<option value="2">test2</option>
<option value="3" selected="selected">test3</option>
<option value="4">test4</option>
<option value="5">test5</option>
</select>
</div>
<div style="border:solid 1px red;" >
第2种:在加载完span和select时,将select2的值给span<br />
<span id="spanSelect2" ></span>
<select id="select2" style="display:none;" >
<option value="1">test1</option>
<option value="2">test2</option>
<option value="3" selected="selected">test3</option>
<option value="4">test4</option>
<option value="5">test5</option>
</select>
<script type="text/javascript">
//在加载完span和select时,将select2的值给span
var select2 = document.getElementById("select2");
var txt = select2.options[select2.selectedIndex].text;
document.getElementById("spanSelect2").innerHTML = txt;
</script>
</div>
<input type="button" onclick="getValue()" value="取得值" />
</div>
</body>
</html>
两种方法,看着办吧。
<span style="position:relative">
<select><option value="1">1</option><option value="2">2</option><option value="3">3</option></select>
<div style="position:absolute;width:100%;height:100%;left:0px;top:0px;background:#fff;opacity:0;filter:alpha(opacity=0)"> </div>
</span>
还有 页面原有的readonly不能改变样子!所以我说不能用disabled
<body>
<select >
<option>1</option>
<option selected>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</bodu>
</html>只显示2 并且不可点击1 3 4 5
如何绑定onchange,onfocus事件,不得焦点,不响应change事件
给select分配个ID,根据其它界面传来的值在body onLoad事件时动态Remove select的Child,然后把仅剩的Child设定selected属性,这样用户页面的下拉框里就只有一个值了。
<span style="position:relative">
<select onfocus="this.blur();"><option value="1">1</option><option value="2">2</option><option value="3">3</option></select>
<div style="position:absolute;width:100%;height:100%;left:0px;top:0px;background:#fff;opacity:0;filter:alpha(opacity=0)"> </div>
</span>
忽悠用户啊?既然不能先,是定值。为什么不用 span input 这些标签
<body>
<select >
<option disabled>1</option>
<option selected>2</option>
<option disabled>3</option>
<option disabled>4</option>
<option disabled>5</option>
</select>
</body>
</html>
在Action里面获取会报空指针异常