Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.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/2/jquery/78.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
Javascript 脚本不是';你不能获取内部HTML吗?_Javascript_Jquery_Html - Fatal编程技术网

Javascript 脚本不是';你不能获取内部HTML吗?

Javascript 脚本不是';你不能获取内部HTML吗?,javascript,jquery,html,Javascript,Jquery,Html,我这里有这个HTML <div id="team_players"> <h3>Players</h3> <button class="bold-btn" onclick="teamAct('player_list');">Refresh List ↻</button> <table> <thead> <tr> <th>Name(s)</

我这里有这个HTML

<div id="team_players">
  <h3>Players</h3>
  <button class="bold-btn" onclick="teamAct('player_list');">Refresh List ↻</button>
  <table>
    <thead>
      <tr>
        <th>Name(s)</th>
        <th>Inventory</th>
        <th>Playtime</th>
        <th>Notes</th>
        <th>Actions</th>
      </tr>
    </thead>
    <tbody>
      <tr data-player-ref="1">
        <td>Scriptist.<br>Scriptist.<br>HollowPresenter<br></td>
        <td><img src="img/item/item_shredder_g.png"><img src="img/item/block.png"></td>
        <td>4:13:20</td>
        <td><u style="color: #0F0">Online</u><u style="color: #0FF">Captain [1]</u><br><u style="color: #F00">Possible Alias of Snogg &lt;0&gt; [BANNED]</u></td>
        <td><br></td></tr><tr data-player-ref="13">
        <td>Snogg<br></td>
        <td></td>
        <td>9:01</td>
        <td><u style="color: #F00">Banned</u><br><u style="color: #FFF">Possible Alias of HollowPresenter &lt;0&gt;</u></td>
        <td><button class="btn-small btn-orange" onclick="teamAct('unban',13);">Un-Ban</button></td>
      </tr>
    </tbody>
  </table>
</div>
为什么这不能得到innerHTML?它应该返回这样的东西

<td><img src="img/item/item_shredder_g.png"><img src="img/item/block.png"></td>

.innerHTML
上有一个无关的
[0]
,它只获取第一个字符

var Userinventory=document.querySelectorAll('tr[data player ref]>td:n类型(2)';
Userinventory.forEach(getinventoryitems)
函数getinventoryitems(项,索引){
var useritems=item.innerHTML;
日志(useritems);
}

球员
刷新列表↻
姓名
库存
游戏时间
笔记
行动
编剧。
编剧。
HollowPresenter
4:13:20 OnlineCaptain[1]
可能是Snogg 0的别名[禁止]
Snogg
9:01 已禁止
HollowPresenter 0的可能别名 联合国禁令
有一种更简单的方法可以做到这一点,
使用相应的javascript方法访问html表:

document.querySelector('table tbody').rows[0].cells[1].innerHTML

console.log(document.querySelector('table tbody')。行[0]。单元格[1]。innerHTML)
.as控制台{背景色:黑色!重要;颜色:石灰;}
.作为控制台包装{最小高度:100%!重要;顶部:0;}

球员
刷新列表↻
姓名
库存
游戏时间
笔记
行动
编剧。
编剧。
HollowPresenter
4:13:20 OnlineCaptain[1]
可能是Snogg 0的别名[禁止]
Snogg
9:01 已禁止
HollowPresenter 0的可能别名 联合国禁令
我在谷歌的控制台上看到“未定义”。投票决定以“无法重现的问题”结束。OP在一个通常没有的属性中添加了一个额外的
[0]
,因此更像是一个“打字错误”问题,对未来的用户没有实际价值。当我删除它时。在“[0]”中,它根本不记录任何日志。只是一个没有文本的空白框。不是说“未定义”。奇怪的是,我把它放在一个片段中,它显示HTML是我在编辑之前复制的。另外,看起来编辑全是空白更改,不起作用。我注意到你的anwser日志也只有一个空白框。为了确保它不是什么疯狂的浏览器,你能试试做
console.log('aaa')
document.querySelector('table tbody').rows[0].cells[1].innerHTML