请教怎么用js实现下面要求 var pattern = /6/;遍历所有option 看是否匹配 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 能不能具体点,写下code,谢谢 translate(val){ var test = document.getElementById("test"); //select要加id属性 for(var i=0;i<test.options.length;i++) { if(test.options[i].text.indexOf("6") == -1) {test.options.remove(i);} }} 可把"6"换成val 代码经过测试<script type="text/javascript">function FindOption( oText ){ var array = new Array("1111","11123","322213","45664","456699","777888"); var oSelect = document.getElementById("select1"); oSelect.options.length = 1; for(var i=0; i < array.length; i++) { var pattern = new RegExp(oText.value); if(pattern.test(array[i])) { var option=new Option(array[i],i); oSelect.options.add(option); } }}</script><input type="text" id="text1" onpropertychange="FindOption(this)"><select id="select1" style="width:150px"><option value=""></option></select> 我用了的code,输入6出来是1111/322213/456699,不符合要求呢,不知道test.options[i].text.indexOf("6") == -1是什么意思?请教“我本有心” translate(val) { var test = document.getElementById("test"); //select要加id属性 for(var i=0;i <test.options.length;i++) { if(test.options[i].text.indexOf("6") == -1) {test.options.remove(i);} } } test.options[i].text.indexOf("6") == -1 说明option的文本不含有字串6这样写应该是OK的吧? jqery中onclick="fun()"中的$(this)是什么 jquery的jqgrid控件小问题 鼠标悬停在一个图片提交按钮上出现提示文本 如何让程序延迟1秒执行,并且只执行1次 E-mail邮件体的协议格式怎么写? 又是“缺少对象” 如何禁止网页被某个网站进行恶意链接??? 浏览器中显示的图片左上角那个保存,打印,发送,收藏的工具栏为什么有的图有,有的图没有呢 javascript如何判断对象是否存在? 如何让页间传值不显示或加密?? 找师傅! 如何获取焦点问题?
translate(val)
{
var test = document.getElementById("test"); //select要加id属性
for(var i=0;i<test.options.length;i++)
{
if(test.options[i].text.indexOf("6") == -1) {test.options.remove(i);}
}
}
可把"6"换成val
<script type="text/javascript">
function FindOption( oText )
{
var array = new Array("1111","11123","322213","45664","456699","777888");
var oSelect = document.getElementById("select1");
oSelect.options.length = 1;
for(var i=0; i < array.length; i++)
{
var pattern = new RegExp(oText.value);
if(pattern.test(array[i]))
{
var option=new Option(array[i],i);
oSelect.options.add(option);
}
}
}
</script>
<input type="text" id="text1" onpropertychange="FindOption(this)">
<select id="select1" style="width:150px">
<option value=""></option>
</select>
translate(val)
{
var test = document.getElementById("test"); //select要加id属性
for(var i=0;i <test.options.length;i++)
{
if(test.options[i].text.indexOf("6") == -1) {test.options.remove(i);}
}
} test.options[i].text.indexOf("6") == -1 说明option的文本不含有字串6
这样写应该是OK的吧?