2014-01-13 47 views
0

我jQuery的功能有一定的選擇框代碼:如何從另一個jQuery函數調用jQuery函數onchange事件

$("select#opt11") 
.html(JSON_OPTION(geography,"Continent")) 
.change(function(){ 
    $('td#1').find("#opt12,#opt13,#opt14,#opt15,#b11,#b12,#b13,#b14").remove(); 
    $('td#1').append('<br id="b11"><select id="opt12" style="width: 130px">   </select>'); 
    callService(this.value); } 

這callService必須是像另一個jQuery函數:

$(function() { 
    $.ajax({ 
     type:'GET', 
     url:'URL/Services/rest/GWSWrapper/GetChartData', 
     dataType: 'json', 
     success:function(data,textStatus,jqXHR){ 
      if(jqXHR.status==200){ 
       alert(jqXHR.status); 
       $('#graphContainer').highcharts(data[0]); 
      } 
      if(jqXHR.status==500) 
       alert("Fail");      
     } 
    }); 
}); 

我不能夠獲得相同的正確語法。

回答

1

嘗試把你的代碼中的函數,然後調用該函數:

function callService(value) 
{ 
$.ajax({ 
    type:'GET', 
    url:'URL/Services/rest/GWSWrapper/GetChartData', 
    dataType: 'json', 
    success:function(data,textStatus,jqXHR){ 
     if(jqXHR.status==200){ 
      alert(jqXHR.status); 
      $('#graphContainer').highcharts(data[0]); 
     } 
     if(jqXHR.status==500) 
      alert("Fail");      
    } 
}); 
} 
+0

由於一噸的Bhushan – user2093576

+0

@ user2093576歡迎您。 – Bhushan