2016-11-19 50 views
0

如何在變量中獲取jquery ui selectmenu值? 我試圖用這個代碼:在變量中獲取jQuery UI選擇菜單值

<link href="http://code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css" rel="stylesheet" /> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
    <script src="http://code.jquery.com/ui/1.11.0/jquery-ui.js"></script> 


    <select name ="option" id="firstOption"> 
    <option value="0">First Option</option> 
    <option value="1">Second Option</option> 
    </select> 
$("#firstOption").selectmenu(change: function(event, data) { 
     var chartBkgColor=$(this).val(); 
     if (chartBkgColor==0){ 
      alert ("0"); 
     }else if (chartBkgColore==1){ 
      alert ("1"); 
     }); 

回答

0

我想通了

<head> 
    <link href="http://code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css" rel="stylesheet" /> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
    <script src="http://code.jquery.com/ui/1.11.0/jquery-ui.js"></script> 
<head> 
<body> 
    <select name ="option" id="firstOption"> 
    <option value="0">First Option</option> 
    <option value="1">Second Option</option> 
    </select> 
<javascript> 
$("#firstOption").selectmenu(change: function(event, data) { 
     var chartBkgColor=$('#firstOption').val(); 
     if (chartBkgColor==0){ 
      alert ("0"); 
     }else if (chartBkgColore==1){ 
      alert ("1"); 
     }); 
</javascript>