【问题标题】:Ajax loaded content div class is not applied未应用 Ajax 加载的内容 div 类
【发布时间】: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');
    });

【问题讨论】:

    标签: ajax class html


    【解决方案1】:

    关于注册页面的一些事情,我不确定它是如何工作的。修复应该是将您的频道点击功能更改为与您的第一个相同并使用 .on('click') 选项。

    找到了一些相关的阅读材料。 https://learn.jquery.com/events/event-delegation/

    【讨论】:

    • 我在玩,最后尝试了。我认为它把我带到了正确的方向..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-17
    • 1970-01-01
    • 2018-10-14
    • 1970-01-01
    • 2017-03-15
    • 2013-01-19
    • 1970-01-01
    相关资源
    最近更新 更多