我正在<div>
通过 Ajax 附加一个。<div>
在通过 Ajax 动态附加后,可以应用 jQuery 函数和 CSS 。得到正确附加,<div>
但 jQuery 函数和 CSS 没有为此加载<div>
。我该怎么做?
AJAX 代码
$.ajax({
type: "POST",
url: "/dashboard/",
data : { 'widgets_list' : widgets_list },
success: function(result){
console.log(widgets_list);
$("#column1").append(result); // div gets appended.
}
});
视图.py
HTMLstr += "<div class='portlet'><div class='portlet-header'>Live Graph</div>" + \
"<div class='portlet-content' id='live_graph' style='height: 270px margin: 0 auto'>" + \
"</div></div>"
return HttpResponse(HTMLstr)
jQuery functions
需要申请的是:-
$(function() {
$( ".column" ).sortable({
connectWith: ".column",
handle: ".portlet-header"
});
$( ".portlet" ).addClass( "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" )
.find( ".portlet-header" )
.addClass( "ui-widget-header ui-corner-all" )
.prepend( "<span class='ui-icon ui-icon-minusthick'></span>")
.end()
.find( ".portlet-content" );
$( ".portlet-header .ui-icon" ).click(function() {
$( this ).toggleClass( "ui-icon-minusthick" ).toggleClass( "ui-icon-plusthick" );
$( this ).parents( ".portlet:first" ).find( ".portlet-content" ).toggle();
});
});
and 1 more jQuery function.
CSS
<style>
body { min-width: 520px; }
.column { width: 170px; float: left; padding-bottom: 100px;}
.portlet { margin: 0 1em 1em 0; }
.portlet-header { margin: 0.3em; padding-bottom: 4px; padding-left: 0.2em; }
.portlet-header .ui-icon { float: right; }
.portlet-content { padding: 0.4em; max-height: 270px;}
.ui-sortable-placeholder { border: 1px dotted black; visibility: visible !important; height: 50px !important; }
.ui-sortable-placeholder * { visibility: hidden; }
</style>
更新的问题
HTML
<div class="column span4" id="column1">
<div class="portlet">
<div class="portlet-header">Line Chart</div>
<div class="portlet-content" id="basic_line" style="height: 270px"></div>
</div>
</div>
jQuery 函数
$(function () { // I replaced this line with $("#portlet").on('click', '#live_graph',function() {.... But it didnt work!!
$(document).ready(function() {
Highcharts.setOptions({
global: {
useUTC: false
}
});
var chart;
$('#live_graph').highcharts({
chart: {
type: 'spline',
animation: Highcharts.svg, // don't animate in old IE
marginRight: 10,
events: {
load: function() {
// set up the updating of the chart each second
var series = this.series[0];
setInterval(function() {
var x = (new Date()).getTime(), // current time
y = Math.random();
series.addPoint([x, y], true, true);
}, 1000);
}
}
},
title: {
text: 'Live random data'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150
},
yAxis: {
title: {
text: 'Value'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) +'<br/>'+
Highcharts.numberFormat(this.y, 2);
}
},
legend: {
enabled: false
},
exporting: {
enabled: false
},
series: [{
name: 'Random data',
data: (function() {
// generate an array of random data
var data = [],
time = (new Date()).getTime(),
i;
for (i = -19; i <= 0; i++) {
data.push({
x: time + i * 1000,
y: Math.random()
});
}
return data;
})()
}]
});
});
});
我希望这个 highchart 在 portlet-content 中,但我做不到。我哪里错了?
.on( events [, selector ] [, data ], handler(eventObject) )
可以ready
是活动吗?