2014-07-04 17 views
1

Highchart容器如何在點擊時從highchart事件中的html元素觸發jQuery的onchange函數?

$('#container').highcharts({ 
       /// code goes here 

       plotOptions:{ 
       series: { 
        cursor: 'pointer', 
        point: { 
         events: { 
          click: function() { 
           // 
           if(this.series.name=="Positive") { 
            <%if(posTitle.get(0).equals("NoValue")){ 
             //do nothing 
            }else{ 
            %> 
            $report.html(
              '<table>'+ 
              '<tr><td><b>Sentiment</b></td><td><b>News</b></td><td><b>Date</b></td><td><b>News Courtesy</b></td><td><b>User Opinion</b></td></tr>' + 
              <% for(int tempTitle=0;tempTitle<1;tempTitle++){%> 
              '<tr><td>'+this.series.name+'</td><td><a href='+"<%=posTitle.get(tempTitle)%>"+' target = "_blank">'+"<%=posNews.get(tempTitle)%>"+'</a></td><td>'+"<%=posDate.get(tempTitle)%>"+'</td><td>iproperty.com.sg</td><td>***<select class="check" id="op1" >***<option value="0.5" selected="selected">Positive</option><option value="1">Very Positive</option><option value="0">Neutral</option><option value="-0.5">Negative</option><option value="-1">Very Negative</option></select></td></tr>'+ 
              <%}%> 
              '</table>'); 
            <%}%> 
           } 

所以,當我嘗試觸發電平變化上面$ report.html內選擇()。它不調用下面的函數。 所以功能是這樣的:

$(document).ready(function() { 
     $('.check').on('change',function() 
     { alert(this); 
      $.ajax({ 
       type: "post", 
       url: "mainPageForOpinion.jsp", //this is my servlet 
       data: { 
        output: $(this).val() 
       }, 
       success: function(){ 
        $('#output').html("Updated"); 
       } 
      }); 
     }); 
    }); 

有人可以幫助我! 謝謝

+0

error'屬性添加到'你的Ajax來幫助自己調試,你需要指向一個'WebMethod'在你的servlet,而不是在servlet本身 –

+0

@大衛:接受但主要關心的不是ajax,而是onchange事件,儘管我綁定了類,但它甚至不會觸發該函數。 – Vigs

+0

解決。問題在於腳本應該放在$ report.html()中,以便通過onclick事件加載$ report.html()來觸發事件。 – Vigs

回答

0

只需撥打$(".check").change()$report.html(...) - 確保,即改變你在DOM創建新元素後調用。

0

由於您正在動態創建select標記,並且class=check需要使用文檔對象綁定更改事件。請參見下面的jQuery:

$(document).ready(function() { 
     $(document).on('change','.check',function()// bind change event using document object 
     { alert(this); 
      $.ajax({ 
       type: "post", 
       url: "mainPageForOpinion.jsp", //this is my servlet 
       data: { 
        output: $(this).val() 
       }, 
       success: function(){ 
        $('#output').html("Updated"); 
       } 
      }); 
     }); 
    }); 
+0

它不工作..我個人覺得onchange射擊是從$ report.html(.. ),它不能識別文檔中有一個函數,因爲它本身處於圖表中數據點的功能點擊。 – Vigs

0

問題是腳本應該放在$ report.html()中以觸發事件,因爲$ report.html()是通過onclick事件加載的。

小提琴:jsfiddle.net/H32qN/4

相關問題