我想實現(xiàn)的效果是左邊選中了一個選項,右邊那個選項相同的就會變藍,右邊選中也是這樣。要JS做,不用JQuery,我做到這里就做不下去了,求大神幫我看看,指導我一下<!DOCTYPE?html>
<html>
<head>
<meta?charset="utf-8">
<title>按鈕</title>
<meta?name="viewport"?content="width=device-width,?initial-scale=1.0">
<style?type="text/css">
select?{
????width:?100px;
????height:?30px;
????line-height:?30px;
????border:?#ccc?1px?solid;
????border-radius:?3px;
}
input[type="button"]?{
????width:?100px;
????height:?30px;
????line-height:?30px;
????background:?#333;
????color:?#fff;
????border:?none;
????border-radius:?3px;
}
input.active?{
????background:?#09F;
}
</style>
<script?type="text/javascript">
function?each(){
????var?Menu?=?document.getElementById("menu");
????var?listNum=Menu.children.length||Menu.childNodes.length;
????for(var?i=0;i<listNum;i++){
????????var?btnI=document.getElementById("btn"+(i+1));
????????(function(i){
????????????btnI.onclick?=?function(){
????????????????var?btnI=document.getElementById("btn"+(i+1));
????????????????var?cityName=btnI.value;????
????????????????var?active?=?document.querySelector("#form1>input.active");
????????????????if(active!=null){
????????????????????active.className="";
????????????????}?
????????????????btnI.className="active";
????????????????alert(aaa)
????????????}
????????})(i);???????
????}
}
function?selectInput(selecte){????
????????var?Menu?=?document.getElementById("menu");??
????????var?Option=Menu.options[Menu.selectedIndex].text;??
????????console.log(Option);
}?
var?aaa=selectInput();
window.onload?=?function(){
????????each();
}
</script>
</head>
<body>
<form?id="form1"?name="form1"?method="post"?action="">
??<label?for="menu"></label>
??<select?name="menu"?id="menu"?onChange="selectInput(this)">
????<option>溫江區(qū)</option>
????<option>雙流區(qū)</option>
????<option>龍泉驛區(qū)</option>
????<option>新都區(qū)</option>
????<option>郫縣</option>
????<option>表白江區(qū)</option>
??</select>
??<input?type="button"?id="btn1"?value="溫江區(qū)"?/>
??<input?type="button"?id="btn2"?value="雙流區(qū)"?/>
??<input?type="button"?id="btn3"?value="龍泉驛區(qū)"?/>
??<input?type="button"?id="btn4"?value="新都區(qū)"?/>
??<input?type="button"?id="btn5"?value="郫縣"?/>
??<input?type="button"?id="btn6"?value="表白江區(qū)"?/>
</form>
</body>
<script?type="text/javascript">
</script>
</html>我得到了昨天選項里的內(nèi)容,但是不知道怎么和右邊的cityname進行相等的判斷。
用JS做一個小demo時卡住了,求大神們幫忙
一杯2塊的奶茶
2016-04-28 11:03:51