jQuery .html()在ie7中不显示任何数据,但是ie8可以工作 [英] jQuery .html() not displaying any data in ie7, but ie8 works

查看:79
本文介绍了jQuery .html()在ie7中不显示任何数据,但是ie8可以工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

那么谁对ie7没有问题?

So who doesn't have issues with ie7 ?

似乎我无法让ie7识别一些数据.

It seems that I cannot get ie7 to recognize some data.

我为我的客户创建了一个wordpress主题,这使他们可以通过管理员在wordpress meta fields中添加额外的信息,以便他们可以显示额外的信息.

I have created a wordpress theme for a client of mine, and this allows them to put in extra information in the wordpress meta fields through the admin so they can display extra info.

我写了一个小jQuery脚本,它查看图像alttitle来收集此信息并将其写入div.

I have written a small jQuery script that looks at an images alt and title to gather this info and write it into a div.

下面是我的脚本.

<script type="text/javascript">
    //<![CDATA[
    jQuery(document).ready(function(){
      var title = jQuery('.attachment-post-thumbnail').attr('title');
      var alt = jQuery('.attachment-post-thumbnail').attr('alt');
      jQuery('#vehicle-alt').html('<h2 class="car-detail">'+title+'</h2><p>'+alt+'</p>');
    });
    //]]>
</script>

当我查看ie7中的源代码时,没有传递任何信息.

When i look at the source code in ie7, there is no information that has been passed.

div就像<div id="vehicle-alt"></div>

推荐答案

.html()方法使用浏览器的innerHTML属性.某些浏览器可能不会生成完全复制提供的HTML源代码的DOM.

.html() method uses the browser's innerHTML property.Some browsers may not generate a DOM that exactly replicates the HTML source provided.

似乎jQuery html()方法在现有DOM对象上调用方法empty().因此,请尝试在div上使用empty()而不是html(),然后尝试ap​​pend().例如

It seems that jQuery html() method calls the method empty() on an existing DOM object. Hence try empty() instead of html() on the div, and try append(). For example

 $('#vehicle-alt').append('html content');

还请尝试使用JQuery提供的其他 dom操纵方法.

Also please try other dom manipulation menthods provided from JQuery.

这篇关于jQuery .html()在ie7中不显示任何数据,但是ie8可以工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆