【问题标题】:Jquery/ajax loaded table not showing on IE 9IE 9 上未显示 Jquery/ajax 加载的表
【发布时间】:2018-01-17 01:09:59
【问题描述】:

我有一个由 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)
    })

有什么办法可以做得更好吗?

谢谢。

【问题讨论】:

  • 你为什么不试试jQuery.load

标签: jquery ajax html-table


【解决方案1】:

试试

$('#daily_result').load('ajax-functions.php', {
            'action':'getdailyStatus'
        }, function(){
            var rowid = $('#daily_result tr:first-child').attr('id')
            getDetails(rowid)
        });

【讨论】:

  • 是的。它能够从 '#daily_result tr:first-child' 获取并执行 getDetails(rowid) 函数
猜你喜欢
  • 2012-03-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-20
相关资源
最近更新 更多