选择中的Prototype make选项由提供的值选择

Zel*_*lid 2 javascript prototypejs

使用Protype填充选项(国家/地区列表):

for (var i = 0; i < j.length; ++i) {
            var opt = new Element('option', {value:j[i].country})
            opt.innerHTML = j[i].country_name;            
            country.appendChild(opt);
}
Run Code Online (Sandbox Code Playgroud)

现在我需要选择按价值选择,像某些东西一样

function selectByValue(countryCode) {
   // make option selected where option value == countryCode
}
Run Code Online (Sandbox Code Playgroud)

如何用Prototype做到这一点?

sst*_*ger 7

为了回答你的问题,"你是否更直接地使用Prototype",更改:

document.getElementById('country').value=countryCode
Run Code Online (Sandbox Code Playgroud)

至...

$('country').value = countryCode;
Run Code Online (Sandbox Code Playgroud)

不过,他们都做同样的事情.