简体   繁体   English

jQuery追加和jQuery HTML在IE 7或8中不起作用

[英]jquery append and jquery html not working in IE 7 or 8

I have the following code in an external JavaScript file that is called within <head> : 我在<head>内调用的外部JavaScript文件中具有以下代码:

function dailyDealWidget() {
    $.getJSON('http://myurlhere.com?_render=json', function(data) {

        $('#dd-thumb').append('<img src="'+data.value.items[0].deals.deal.splashpagemainimage+'" />');
        $('#dd-description').append(data.value.items[0].deals.deal.offer+' from '+data.value.items[0].deals.deal.merchantname);
        $('#dd-value').append('$'+data.value.items[0].deals.deal.productvalue);
        $('#dd-discount').append(data.value.items[0].deals.deal.totaldealcount+'%');
        $('#dd-price').append('$'+data.value.items[0].deals.deal.saleprice);
        $('#dd-sold').append(data.value.items[0].deals.deal.inventorytaken+' Sold');
    }); //End json
}

Within <body> I have this: <body>我有这个:

 <script type="text/javascript">dailyDealWidget()</script>
 <div id="dd-widget"></div>`
    <div id="dd-widget">
        <div id="dd-container">
            <div id="dd-thumb"></div>
            <div id="dd-infobox">
                <div id="dd-description"></div>
                <table width="165px" cellpadding="0" cellspacing="0">
                    <tr>
                        <th>Value</th>
                        <th>Discount</th>
                        <th>Save</th>
                    </tr>
                    <tr>
                        <td id="dd-value"></td>
                        <td id="dd-discount"></td>
                        <td id="dd-price"></td>
                    </tr>
                    <tr>
                        <td colspan="3" id="dd-sold"></td>
                    </tr>                    
                </table>   
            </div>
            <div style="clear:both;"></div>
        </div><!--End container-->
    </div><!--End dd-widget-->

It appears that .append() is not adding the content to the desired locations in IE. 看来.append()并未将内容添加到IE中的所需位置。 I've also tried using .html() rather than .append() but without any luck. 我也尝试过使用.html()而不是.append()但是没有任何运气。

There are no errors in the console... both in Firebug and in IE's developer tools. 控制台中没有错误...在Firebug和IE开发人员工具中均如此。

Any help would be appreciated. 任何帮助,将不胜感激。

加载页面后,尝试调用dailyDealWidget。

.append() & .html() DO work in IE 7 & 8, so this is not the problem. .append().html()可以在IE 7和8中正常工作,所以这不是问题。 Have you tested to make sure that the callback function for getJSON is actually being called? 您是否进行过测试以确保确实调用了getJSON的回调函数? Have you examined the actual strings being passed to .append() prior to trying to perform the append itself? 在尝试执行附加操作之前,您是否检查了传递给.append()的实际字符串?

Try logging something to the console at the beginning of the $.getJSON callback function to make sure that's actually running, and then try logging the strings you're passing to the .append() functions. 尝试在$.getJSON回调函数的开头将某些内容记录到控制台,以确保该记录实际上正在运行,然后尝试记录传递给.append()函数的字符串。

Are the DIV appends working and just not the TD appends? DIV附件在起作用,而TD附件在起作用吗? if so, try to re-draw the whole TR row into one variable then replace the existing row. 如果是这样,请尝试将整个TR行重新绘制到一个变量中,然后替换现有行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM