0

Jquery/AJAX によってロードされたテーブルがあります

function initializeDaily() {
jQuery.post(
        'ajax-functions.php', 
        {
            'action':'getdailyStatus'
        }, 
        function(response){
            var html = response
            $('#daily_result').append(html) //append to table #daily_result

            var rowid = $('#daily_result tr:first-child').attr('id')

            getDetails(rowid)
        })
}

これは、IE9 ではなく、他のすべてのブラウザーで機能します。getDetails(rowid) は機能するので、構文エラーはないと思います

一方、私がこれをした場合:

function initializeDaily() {
jQuery.post(
        'ajax-functions.php', 
        {
            'action':'getdailyStatus'
        }, 
        function(response){
            var html = '    <table id="daily_result" cellspacing="0">'+"\n"
            html += response
            html += '   </table>'+"\n"  
            $('#data_scroll').html(html) //div that holds the table

            var rowid = $('#daily_result tr:first-child').attr('id')

            getDetails(rowid)
        })
}

テーブルは正常に読み込まれますが、$("#daily_result").on("click", "tr", function(event))機能しません。

これを回避する方法はありますか?何が悪かったのか誰か教えてくれれば大変助かります =)

**編集

わかりました...なんとか動作させることができました。ただし、これが最善の方法だとは思いません。

これは私がしたことです:

 jQuery.post( //its still post
    'ajax-functions.php', 
    {
        'action':'getdailyStatus'
    }, 
    function(response){
        var html = response

        $('#data_scroll').html(html)

        var rowid = $('#daily_result tr:first-child').attr('id')

        //moved my event handler here; after the loading of the table
        $("#daily_result").on("mouseenter mouseleave", "tr", function(event){
            if(event.type == "mouseenter"){
                $(this).css("background","#999")
                $(this).css("color","#FFF")
            }
            else {
                $(this).removeAttr('style')
            }
        })
        getDetails(rowid)
    })

これを改善する方法はありますか?

ありがとうございました。

4

1 に答える 1

0

試す

$('#daily_result').load('ajax-functions.php', {
            'action':'getdailyStatus'
        }, function(){
            var rowid = $('#daily_result tr:first-child').attr('id')
            getDetails(rowid)
        });
于 2013-02-18T04:46:13.173 に答える