【发布时间】:2014-04-11 15:22:07
【问题描述】:
我有一个页面,其中有几个通过 JS-Graph.It 以流程图连接的 div。当您单击其中一个 div 时,我希望它 1)在特殊 div 中生成文本 2)通过附加到每个 div 中的两个类“block”和“channel”的单击函数生成弹出窗口。这在页面是静态的时候有效。
当我通过单击按钮添加 ajax 并添加更多 div 时,两个类中只有一个出现在 HTML 源代码中。 “频道”不再可见,单击频道类 div 时生成弹出窗口的功能不再起作用...
AJAX 调用:
$("#trace").bind('click', $.proxy(function(event) {
var button2 = $('#combo').val();
if(button2 == 'default') {
var trans = 'Default View';
}
if(button2 == 'abc') {
var trans = 'abc';
}
$.ajax({ // ajax call starts
url: 'serverside.php', // JQuery loads serverside.php
data: 'button2=' + $('#combo').val(), // Send value of the clicked button
dataType: 'json', // Choosing a JSON datatype
success: function(data) // Variable data constains the data we get from serverside
{
JSGraphIt.delCanvas('mainCanvas');
$('.test').html('<h1>' + trans + '</h1>'); // Clear #content div
$('#mainCanvas').html(''); // Clear #content div
$('#mainCanvas').append(data);
JSGraphIt.initPageObjects();
}
});
return false; // keeps the page from not refreshing
}, this));
DIV 类:(在 index.php 中有效,但在 transactions.php 中无效)
// Boxes
while($row = sqlsrv_fetch_array($result))
{
echo '<div id="'.$row['id'].'_block" class="block channel" style="background:';
功能:
$(document).on('click', '.block', $.proxy(function(event) {
var input = $(event.target).attr('id');
var lines = input.split('_');
var button = lines[0];
$.ajax({
url: 'srv.php',
data: 'button=' + button,
dataType: 'json',
success: function(data)
{
$('#content').html('');
$('#content').append(data);
}
});
return false;
}, this)); // End Application Details
$(".channel").click(function () {
alert('channel');
});
【问题讨论】: