[英]How to fire a jquery function onchange from an html element in highchart event on click?
Highchart container 高图容器
$('#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>');
<%}%>
}
So when I try to fire the above onchange select within $report.html() . 因此,当我尝试触发上述onchange时,请在$ report.html()中进行选择。 It is not calling the below function.
它没有调用下面的函数。 so the function is this:
所以功能是这样的:
$(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");
}
});
});
});
Can someone help me! 有人能帮我吗! Thanks
谢谢
As you are creating select
tag with class=check
dynamically, you need to bind change event using document object. 在动态创建带有
class=check
select
标签时,需要使用文档对象绑定更改事件。 See below jQuery : 见下面的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");
}
});
});
});
只需在$report.html(...)
$(".check").change()
之后调用$(".check").change()
-确保在DOM中创建新元素后调用该更改。
Problem was the script should be inside the $report.html() to fire the event as the $report.html() is loaded over onclick event. 问题在于脚本应该在$ report.html()内以触发事件,因为$ report.html()是通过onclick事件加载的。
fiddle: jsfiddle.net/H32qN/4 小提琴:jsfiddle.net/H32qN/4
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.