-6

私が持っている状況がありますtd

<td id="divInTimeStamp-5-2" style="background: none repeat scroll 0% 0% red;">
    12:55 PM 
    <span><img style="vertical-align: middle;" src="/Content/themes/base/images/info.png"><span class="tooltip">Clocked in from: <br>Host: id14011.o2.local<br>IP Address: 10.0.2.49</span></span> 
    <a title="Edit ClockIn Time" class="inline UpdateLink timeSheetIdentity" href="">[ Δ ]</a>
</td>

から値 12:55 PM を取得するにはどうすればよいtdですか?

4

4 に答える 4

2

できるよ

var value = $('#divInTimeStamp-5-2').contents().filter(function(){
    return this.nodeType == 3
}).text()

デモ:フィドル

于 2013-07-15T17:08:00.110 に答える
0
var text = $.trim($('#divInTimeStamp-5-2')[0].firstChild.nodeValue);

デモ

  • [0]DOM 要素への参照を取得します#divInTimeStamp-5-2。の省略形です.get(0)
  • .firstChild最初の子テキスト ノードを取得します。
  • .nodeValueテキスト ノードのコンテンツが含まれます。
  • $.trimクロスブラウザの空白のトリミング用。
于 2013-07-15T17:13:43.350 に答える
0

これを試して:

var cloned = $('#divInTimeStamp-5-2').clone();
cloned.find('*').remove();
var time = cloned.text();
于 2013-07-15T17:08:17.377 に答える