用js往select里面赋值的问题,很简单 现在我有一个需求,现在我有一个select框 我要用js给这个select赋值 要显示的值在这个select里面已经有了 但是问题是我现在赋值text的话等于给select框加了一个选项,但是我现在要复制的时候只取到了select框里面的name,没有Value请问怎么做? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我感觉我也没说明白 这么说吧我现在有一个select和一个text现在我的select是这样的 <select name="name" orteus="true"> <option></option> <option value="1">AAA</option> </select>我现在想在text里面输入AAA的时候就让select显示AAA,注意text里面不能输入value值怎么做? <input id="text1" type="text" /><select id="name" name="name" orteus="true"> <option></option> <option value="1">AAA</option></select> window.onload = function() { var input = document.getElementById('text1'); input.onkeyup = function() { var select = document.getElementById('name'); for (var i = 0, count = select.options.length; i < count; i++) { if (select.options[i].text == input.value) { select.selectedIndex = i; break; } } } } <script>function test(val){ var sel=document.getElementById('sel'); for(var i=0;i<sel.options.length;i++) { if(sel.options[i].text==val) { sel.options[i].selected=true; break; } }}</script><select id="sel" name="name" orteus="true"> <option> </option> <option value="1">AAA </option></select> <input type="text" stype="width:100px;" onblur="test(this.value)" /> orteus= true 是什么意思呀? 关于修改数量后自动提交的问题 按钮控制DIV中内容左右移动 为什么稍微改一下就无效了? javascriipt 解析json问题,请大家帮忙看看! 模拟双击事件 关于window.open的使用 多个下拉选择框,提交前,判断所有的下拉选择框是否选择 options清除现有项 紧急求助!图片滚动一次就停了 小问题,获得焦点 javaascript 如何 捕获页面 所有的点击事件(包括点击 <a href=""这样的!) 请问各位大虾,WebQQ里面图标拖拉效果是用什么实现的啊?哪位大哥有源码我看看啊?急~~
现在我的select是这样的
<select name="name" orteus="true">
<option></option>
<option value="1">AAA</option>
</select>
我现在想在text里面输入AAA的时候就让select显示AAA,注意text里面不能输入value值
怎么做?
<select id="name" name="name" orteus="true">
<option></option>
<option value="1">AAA</option>
</select>
window.onload = function() {
var input = document.getElementById('text1');
input.onkeyup = function() {
var select = document.getElementById('name');
for (var i = 0, count = select.options.length; i < count; i++) {
if (select.options[i].text == input.value) {
select.selectedIndex = i;
break;
}
}
}
}
<script>
function test(val){
var sel=document.getElementById('sel');
for(var i=0;i<sel.options.length;i++)
{
if(sel.options[i].text==val)
{
sel.options[i].selected=true;
break;
}
}
}
</script>
<select id="sel" name="name" orteus="true">
<option> </option>
<option value="1">AAA </option>
</select>
<input type="text" stype="width:100px;" onblur="test(this.value)" />