日期:2014-05-16 浏览次数:20591 次
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Mighty Gumball (Json)</title>
<meta charset="utf-8">
</head>
<body>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0-beta1.js"></script>
<select id="select">
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
<option value="d">d</option>
<option value="e">e</option>
</select>
<script type = "text/javascript">
$(function(){
var ck = 'd';
$("select option").each(function(){
console.log($(this).val())
if($(this).val() == ck){
$(this).prop('selected',true);
}
})
})
</script>
</body>
</html>
window.onload=function(){
var title = document.getElementById('testid');
for(var i=0;i<title.options.length;i++)
{
if(title.options[i].value == 'test'){
title.options[i].selected = true;
break;
}
}
}