2014-02-21 69 views
-1
function changeHiddenInput(cLeague, nLeague) { 
     console.log(cLeague); 
     console.log(nLeague); 
     var objHidden1 = document.getElementById("hiddenInput1"); 
     var objHidden2 = document.getElementById("hiddenInput2"); 
     objHidden1.value = cLeague.value; 
     objHidden2.value = nLeague.value; 
     var a = objHidden1.value; 
     var b = objHidden1.value; 
     result.innerHTML = a + b; 
    } 

<select class="form-control" id="currentleague" onchange="document.getElementById('currentleague').src=this.value; changeHiddenInput(select)"> 
    <option value="rankicons/bronze5.png" (another value goes somewhere in here)>Bronze V</option> 
</select> 

基本上第一個onchange更改圖像的值,第二個onchange傳入一個值,並做一些數學。有沒有其他方法可以用來評估價值,還是我可以以某種方式傳遞兩個價值觀,並以某種方式將它們分開?我有兩個onchange方法和兩個值我需要通過

+0

不清楚的問題!這是什麼意思? ''? –

回答

0

你可以擁有的價值屬性中的2個值:

<option value="rankicons/bronze5.png,value nr 2">...</option> 

樣品:

function changeHiddenInput(league) { 
     var league_values = league.split(","); 
     var objHidden1 = document.getElementById("hiddenInput1"); 
     var objHidden2 = document.getElementById("hiddenInput2"); 
     objHidden1.value = league_values[0]; 
     objHidden2.value = league_values[1]; 
     var a = objHidden1.value; 
     var b = objHidden1.value; 
     result.innerHTML = a + b; 
     // remove comment and set uniqe id to set img element src 
     //document.getElementById('img_id').src=league_values[0]; 
    } 

HTML:

<select class="form-control" id="currentleague" onchange="changeHiddenInput(this.options[this.selectedIndex].value)"> 
    <option value="rankicons/bronze5.png,value nr 2">...</option> 
</select> 

document.getElementById('currentleague').src=this.value;我刪除,因爲它引用的選擇元素的值本身(相同的ID),並將其添加到您的功能。

相關問題