【问题标题】:jquery ui dynamic table onclick event is not workingjquery ui动态表onclick事件不起作用
【发布时间】:2011-08-30 21:33:07
【问题描述】:

我需要在 jquery 中显示动态表。单击表格数据时,应在下面的文本字段中设置值。

我可以知道如何从动态表中捕获名称并设置到文本字段中

$(document).ready(function() {
    //Retrieve the JSON data from the server using AJAX
    $('#AJAXButton').click(function() {
        $.getJSON('ajax/ajaxtest.js', function(data) {
            processJSON(data);
        });
    });

    //Process and display the JSON data
    function processJSON(data) {
        var output = '<table><tr><th>Name</th><th>Platform</th></tr>';
        //Loop through the Languages 
        $(data.Languages).each(function(index, element) {
            output += '<tr><td class="clickable">' + element.Name + '</td>' + 
              '<td class="clickable">' + element.Platform + '</td></tr>';
        });
        output += '</table>';
        $('#AJAXDiv').html(output);
    }

    $("tr.clickable").live("click", function() {
            $("#name").append(?);
    });

});


<div id="AJAXDiv" style="width:400px; height:600px; background-color:#ddd; border:1px solid black">
</div>

<div>
    <label for="name">Created by: </label> <input id="name" />
</div>

【问题讨论】:

    标签: jquery jquery-ui jquery-click-event tablesorter


    【解决方案1】:

    看看this fiddle,如果它不是你想要的,请告诉我。

    【讨论】:

      【解决方案2】:

      您说您希望在单击该行时发生事件,因此您只需将“可点击”类放在您的行上,而不是每个“td”。然后,单击处理程序可以访问该行中的第一个“td”(您所追求的名称)。

      即。 Demo

      【讨论】:

      • 没问题!如果这是您所追求的,请标记为答案! =)
      猜你喜欢
      • 1970-01-01
      • 2017-02-13
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 2016-02-10
      • 1970-01-01
      • 2011-10-22
      • 2015-03-10
      相关资源
      最近更新 更多