Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/465.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Chrome上使用javascript显示html时数据属性丢失_Javascript_Jquery_Html - Fatal编程技术网

在Chrome上使用javascript显示html时数据属性丢失

在Chrome上使用javascript显示html时数据属性丢失,javascript,jquery,html,Javascript,Jquery,Html,我有javascript代码,可以将html内容加载到div标记中。问题是,在Chrome浏览器中加载数据时,很少有数据属性没有显示。这个问题在Firefox中不会发生。 实际的html代码由perl脚本生成,并脱机写入.html文件 用于加载以下html代码的jquery代码: $.get("/allshows.html", function(html_string) { $( "#imgthingy" ).html(html_string); },'html');

我有javascript代码,可以将html内容加载到div标记中。问题是,在Chrome浏览器中加载数据时,很少有数据属性没有显示。这个问题在Firefox中不会发生。 实际的html代码由perl脚本生成,并脱机写入.html文件

用于加载以下html代码的jquery代码:

$.get("/allshows.html", function(html_string)
   {
      $( "#imgthingy" ).html(html_string);
 },'html');    
<div class="fade-area-2">
    <a href="Under the Dome" data-toggle="modal" data-target="#ShowModal" data-sorting="Under the Dome" data-image="http://assets.fanart.tv/fanart/tv/264492/tvthumb/under-the-dome-51cc511a76f1a.jpg" data-NextEpisode="S3E13" data-Genre="Drama | Science-Fiction | Thriller " data-lastaired="S3E13" data-Premiered="2013-06-24" data-Status="Ended" data-TotalSeasons="0" data-summary="&lt;p&gt;&lt;b&gt;Under the Dome&lt;/b&gt; is the story of a small town that is suddenly and inexplicably sealed off from the rest of the world by an enormous transparent dome. The town&#39;s inhabitants must deal with surviving the post-apocalyptic conditions while searching for answers about the dome, where it came from and if and when it will go away.&lt;/p&gt;" class="nocli">
        <img src="http://assets.fanart.tv/fanart/tv/264492/tvthumb/under-the-dome-51cc511a76f1a.jpg" class="img-rounded" style="width: 140px; height: 140px; margin-right:10px; margin-bottom:10px;">
    </a>
    <a href="Person of Interest" data-toggle="modal" data-target="#ShowModal" data-sorting="Person of Interest" data-image="http://assets.fanart.tv/fanart/tv/248742/tvthumb/person-of-interest-588d94ea26e7f.jpg" data-NextEpisode="S5E13" data-Genre="Drama | Action | Crime " data-lastaired="S5E13" data-Premiered="2011-09-22" data-Status="Ended" data-TotalSeasons="0" data-summary="&lt;p&gt;You are being watched. The government has a secret system, a machine that spies on you every hour of every day. I know because I built it. I designed the Machine to detect acts of terror but it sees everything. Violent crimes involving ordinary people. People like you. Crimes the government considered &quot;irrelevant&quot;. They wouldn&#39;t act so I decided I would. But I needed a partner. Someone with the skills to intervene. Hunted by the authorities, we work in secret. You&#39;ll never find us. But victim or perpetrator, if your number is up, we&#39;ll find you.&lt;/p&gt;" class="nocli">
        <img src="http://assets.fanart.tv/fanart/tv/248742/tvthumb/person-of-interest-588d94ea26e7f.jpg" class="img-rounded" style="width: 140px; height: 140px; margin-right:10px; margin-bottom:10px;">
    </a>
</div>
html代码:

$.get("/allshows.html", function(html_string)
   {
      $( "#imgthingy" ).html(html_string);
 },'html');    
<div class="fade-area-2">
    <a href="Under the Dome" data-toggle="modal" data-target="#ShowModal" data-sorting="Under the Dome" data-image="http://assets.fanart.tv/fanart/tv/264492/tvthumb/under-the-dome-51cc511a76f1a.jpg" data-NextEpisode="S3E13" data-Genre="Drama | Science-Fiction | Thriller " data-lastaired="S3E13" data-Premiered="2013-06-24" data-Status="Ended" data-TotalSeasons="0" data-summary="&lt;p&gt;&lt;b&gt;Under the Dome&lt;/b&gt; is the story of a small town that is suddenly and inexplicably sealed off from the rest of the world by an enormous transparent dome. The town&#39;s inhabitants must deal with surviving the post-apocalyptic conditions while searching for answers about the dome, where it came from and if and when it will go away.&lt;/p&gt;" class="nocli">
        <img src="http://assets.fanart.tv/fanart/tv/264492/tvthumb/under-the-dome-51cc511a76f1a.jpg" class="img-rounded" style="width: 140px; height: 140px; margin-right:10px; margin-bottom:10px;">
    </a>
    <a href="Person of Interest" data-toggle="modal" data-target="#ShowModal" data-sorting="Person of Interest" data-image="http://assets.fanart.tv/fanart/tv/248742/tvthumb/person-of-interest-588d94ea26e7f.jpg" data-NextEpisode="S5E13" data-Genre="Drama | Action | Crime " data-lastaired="S5E13" data-Premiered="2011-09-22" data-Status="Ended" data-TotalSeasons="0" data-summary="&lt;p&gt;You are being watched. The government has a secret system, a machine that spies on you every hour of every day. I know because I built it. I designed the Machine to detect acts of terror but it sees everything. Violent crimes involving ordinary people. People like you. Crimes the government considered &quot;irrelevant&quot;. They wouldn&#39;t act so I decided I would. But I needed a partner. Someone with the skills to intervene. Hunted by the authorities, we work in secret. You&#39;ll never find us. But victim or perpetrator, if your number is up, we&#39;ll find you.&lt;/p&gt;" class="nocli">
        <img src="http://assets.fanart.tv/fanart/tv/248742/tvthumb/person-of-interest-588d94ea26e7f.jpg" class="img-rounded" style="width: 140px; height: 140px; margin-right:10px; margin-bottom:10px;">
    </a>
</div>

html文件的完整粘贴区:

不幸的是,在Chrome中,它看起来是这样的:

<div class="fade-area-2">
  <a href="Under the Dome" data-toggle="modal" data-target="#ShowModal" data-sorting="Under the Dome" data-summary="
    <p>
        <strong>Under the Dome</strong> is the story of a small town that is suddenly and inexplicably sealed off from the rest of the world by an enormous transparent dome. The town's inhabitants must deal with surviving the post-apocalyptic conditions while searching for answers about the dome, where it came from and if and when it will go away.
    </p>" data-image="http://assets.fanart.tv/fanart/tv/264492/tvthumb/under-the-dome-51cc511a76f1a.jpg" data-nextepisode="" data-genre="" data-lastaired="" data-premiered="" data-status="" data-totalseasons="" class="nocli">
    <img src="http://assets.fanart.tv/fanart/tv/264492/tvthumb/under-the-dome-51cc511a76f1a.jpg" class="img-rounded" style="width: 140px; height: 140px; margin-right:10px; margin-bottom:10px;">
    </a>
     <a href="Person of Interest" data-toggle="modal" data-target="#ShowModal" data-sorting="Person of Interest" data-summary="
    <p>You are being watched. The government has a secret system, a machine that spies on you every hour of every day. I know because I built it. I designed the Machine to detect acts of terror but it sees everything. Violent crimes involving ordinary people. People like you. Crimes the government considered &quot;irrelevant.&quot; They wouldn't act so I decided I would. But I needed a partner. Someone with the skills to intervene. Hunted by the authorities, we work in secret. You'll never find us. But victim or perpetrator, if your number is up, we'll find you.</p>" data-image="http://assets.fanart.tv/fanart/tv/248742/tvthumb/person-of-interest-588d94ea26e7f.jpg" data-nextepisode="" data-genre="" data-lastaired="" data-premiered="" data-status="" data-totalseasons="" class="nocli">
    <img src="http://assets.fanart.tv/fanart/tv/248742/tvthumb/person-of-interest-588d94ea26e7f.jpg" class="img-rounded" style="width: 140px; height: 140px; margin-right:10px; margin-bottom:10px;">
  </a>
</div>

加载的html的完整粘贴区(通过console.log):

data nexteposode
数据类型
最新发布的数据
等在Chrome中显示时都会丢失。为什么会这样?我怎样才能避免这种情况

在Firefox中:

镀铬:

它看起来像是在
处截断,但同时也对
数据-
属性重新排序(因此会丢失一些属性)。您能否通过浏览器调试确认
html\u string
是您在
$之后所期望的值。get
?@freedomn-m实际上,不是。当字符串输出到控制台时,Chrome上缺少这些数据属性。同样,在Firefox上,字符串是正确的,与html文件中的字符串完全相同。这意味着问题在于
.get()
而不是
.html()
。可以将
$.get
扩展为完整的
$.ajax({type:'get',url:/allshows.html.
然后可以尝试指定
数据类型:“html”
数据类型:“text”
。不知道为什么会在Chrome中出现这种情况,只是想找到一个替代方法。你能更改php html输出吗?
数据-
属性应该是小写的,我注意到你丢失的是那些不是小写的。@freedomn-m它使用的是
数据类型:“html”
本身