jquery 範例 讓select 隨著 某個TAG內容改變 顯示
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>
<p id="q">a</p>
<select>
<option id="v" value="volvo">Volvo</option>
<option id="s" value="saab" >Saab</option>
<option id="m" value="mercedes" >Mercedes</option>
<option id="a" value="audi">Audi</option>
</select>
<script type="text/javascript">
$(document).ready(function(){
var tmp="#"+$("#q").text();
console.log(tmp);
$(tmp).attr("selected","selected");
});
</script>
</body>
</html>
沒有留言:
張貼留言