1

私のコードは、私が取得しようとしていることをほとんど説明しています:

<div id=player>
    <div class="button hand">&#9658;</div>
    <div class=time>00:00/02:25</div>   
    <div class="timeline hand"><span class="now hand"></span></div>
</div>

<script>

var myPlayer=document.getElementById('player').firstChild;
var playerStatus=(myPlayer.innerText||myPlayer.textContent);

console.log(playerStatus);

</script>

&#9658;コンソールでASCII値を取得する予定です。

ここで必要な微調整

4

2 に答える 2

2

idとの両方がclassあるので、 を使用しますquerySelector()

var myPlayer=document.querySelector('#player > .button.hand');

これには、IE8 で動作するという利点もあります。


innerText/textContentまた、スクリプトの先頭でそれをチェックし、適切なキーを文字列に格納することもショートカットの1 つです。

var text = ("textContent" in document) ? "textContent" : "innerText";

次に、変数で角括弧を使用しtextます。

var myPlayer=document.querySelector('#player > .button.hand');
var playerStatus=(myPlayer[text]);

次に、実際には次のように短縮できます。

var playerStatus=document.querySelector('#player > .button.hand')[text];
于 2015-04-23T21:14:40.220 に答える