<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
</head>
<body>
<p>想要学习的科目</p>
<select name="objname" >
<option value="语文">语文</option>
<option value="数学">数学</option>
<option value="英语">英语</option>
</select>
<p>想要在哪里学习</p>
<select name="where" >
<option value="学校">学校</option>
<option value="家里">家里</option>
<option value="户外">户外</option>
</select>
<p>想要几点开始上课</p>
<select name="time" >
<option value="7">7:00</option>
<option value="8">8:00</option>
<option value="9">9:00</option>
</select>
<script src="jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
var parms={
objname:'英语',
where:'家里',
time:'8'
}
// 初始化
$('select').each(function(){
var name = $(this).attr('name')
if(name){
$('select[name='+name+']').val(parms[name])
}
})
// 模式创建
function setparms(data){
parms[data.name] = data.value;
}
$("select").change(function(){
var name = $(this).attr('name'),
value = $(this).val();
setparms({
name:name,
value:value
})
console.log(parms);
});
</script>
</body>
</html>