0

假设我在某个变量“var”中有值“v”,现在我想显示 Valvo(文本尊重值 v)。有什么建议吗??

4

2 回答 2

0

可能这会帮助你:

//array of varables
var names = ['apple','banana','valvo','blahblahblah']
//this is your variable
var variable = 'v'
//code to display names starting with the character in your variable
for(i=0;i<names.length;i++)
    if(names[i][0] == variable)
        alert(names[i])

这个答案是为了我对你的问题的解释。请享用!

于 2013-03-13T09:42:27.580 回答
0

HTML

<select id="sel">
  <option value="Volvo">Volvo</option>
  <option value="BMW">BMW</option>
</select>

JS

var myvar = 'b';

var elem = document.querySelector('#sel option[value^='+myvar.toUpperCase()+']');
if (typeof elem != 'undefined') {
  elem.selected = true;
}

在这里你可以测试-> http://jsbin.com/ehayav/1

mz

于 2013-03-13T09:24:19.013 回答