Javascript 在jquery中获取TH值

Javascript 在jquery中获取TH值,javascript,jquery,Javascript,Jquery,我试图获取数组中的标题文本,但是通过以下操作,我得到的是值加上th标记,即[value1,value2],我想得到[value1,value2] $('#header').children().each(function(){this.html}); 以下是我的HTML的外观: <tr bgcolor="#cdb79e" id="header"> <th>Origin Code</th> <th>Description</t

我试图获取数组中的标题文本,但是通过以下操作,我得到的是值加上th标记,即
[value1,value2]
,我想得到
[value1,value2]

$('#header').children().each(function(){this.html});
以下是我的HTML的外观:

<tr bgcolor="#cdb79e" id="header">
    <th>Origin Code</th>
    <th>Description</th>
    <th>Notes</th>
    <th>Domain</th>
    <th>Tier</th>
    <th>Engine</th>
    <th>Network</th>
    <th>Platform</th>
    <th>Expansion Tool</th>
    <th>Date</th>
    <th>Imps</th>
    <th>Clicks</th>
    <th>Engine CTR</th>
    <th>Average Position</th>
    <th>Picks</th>
    <th>LP CTR</th>
    <th>GSL Picks</th>
    <th>GSL LP CTR</th>
    <th>Merchant Picks</th>
    <th>Merchant LP CTR</th>
    <th>CPC</th>
    <th>RPC</th>
    <th>RPP</th>
    <th>Cost</th>
    <th>Total Rev</th>
    <th>Margin</th>
    <th>ROI</th>
</tr>

来源代码
描述
笔记
领域
层
引擎
网络
站台
扩展工具
日期
小鬼
咔哒声
发动机中心
平均位置
挑选
LP中心
GSL镐
GSL LP中心
商人挑选
商人有限责任公司
共产党
RPC
RPP
成本
总版次
边缘
投资回报率

假设您的HTML看起来像这样:

<table>
    <thead>
        <tr id='header'>
            <th>Value1</th>
            <th>Value2</th>
        </tr>
    </thead>
</table>

假设您的HTML看起来像这样:

<table>
    <thead>
        <tr id='header'>
            <th>Value1</th>
            <th>Value2</th>
        </tr>
    </thead>
</table>

你可以用正则表达式去掉标签,但那不是很漂亮。感觉应该有更好的选择。HTML是什么样子的?您可以使用
$(this).HTML()
-参见此。
html()
方法使用
innerHTML
属性,不应返回任何外部标记。您可以使用regex剥离标记,但这不是很好。感觉应该有更好的选择。HTML是什么样子的?您可以使用
$(this).HTML()
-参见此。
html()
方法使用
innerHTML
属性,不应返回任何外部标记。工作原理与charm类似!谢谢你也可以使用
map
而不是
each
,它的语法更简洁。
$('#header').children().map(function(){return this.innerHTML;})
更合适:
$('#header').children().map(function(){return$(this.text()).get())
工作起来很有魅力!谢谢你也可以使用
map
而不是
each
,它的语法更简洁。
$('#header').children().map(function(){return this.innerHTML;})
更合适:
$('#header').children().map(function(){return$(this.text()).get()