【问题标题】:Browser doesn't renders table element | jsFiddle example浏览器不呈现表格元素 | jsFiddle 示例
【发布时间】:2018-09-02 01:02:44
【问题描述】:

我的代码使用 James Padolsey 的“jQuery 的跨域模块”发出跨域请求以获取网页源:https://github.com/padolsey/jQuery-Plugins/tree/master/cross-domain-ajax;

然后它选择第一个表并将其附加到现有的 div 中。

但是附加的表格没有正确呈现。谁能看看这个小提琴并告诉我为什么?

http://jsfiddle.net/6ZgRf/

【问题讨论】:

  • 旁注,不要使用全局变量将响应从一个函数传递到另一个函数。将其作为参数传递:stripViewResponse(res.responseText); 并将其作为参数接收 function stripViewResponse(antwort) {...
  • 我知道。但你是对的,其他人可能不会。所以谢谢你的提示。这是更新的 jsFiddle:jsfiddle.net/zjy73

标签: javascript jquery


【解决方案1】:

你正在使用 jQuery.. 所以你可以通过把它变成一个 jQuery 对象来遍历它

function stripViewResponse() {
// Select table element
  var fetchedTable = $(antwort).find('table')[0]; // find first table
// append table
  $('#new').append(fetchedTable);
}

http://jsfiddle.net/6ZgRf/1/

【讨论】:

  • 太棒了!如您所见,我才刚刚开始。非常感谢。
【解决方案2】:

你也可以试试这个

function stripViewResponse() {
// Select table element
    var fetchedTable = $(antwort).find('table').eq(0);
// append table
  $('#new').append(fetchedTable);
}

【讨论】:

  • 谢谢!这与@wirey 建议的几乎相同。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多