如何使用javascript访问特定的div块

时间:2017-04-26 19:22:37

标签: javascript this

$("#jquery_jplayer_1").bind($.jPlayer.event.timeupdate, function(event) {
  if (parseInt(event.jPlayer.status.currentPercentAbsolute) >= 2 ) {
    $("#jquery_jplayer_1").unbind($.jPlayer.event.timeupdate) 
    debugger
  }
});

"这" =

<div id="jquery_jplayer_1" class="jp-jplayer" style="width: 0px; height: 0px;">
    <img id="jp_poster_0" style="width: 0px; height: 0px; display: none;">
    <audio id="jp_audio_0" preload="metadata" src="http://localhost:3000/system/songs/song_files/000/000/054/original/9_horwood_-_gotta_get_out_of_the_city.wav?1492962591" title="Gotta Get Out Of The City"></audio>
</div>

我需要抓住音频src,但我无法获得它。任何提示都将不胜感激!

4 个答案:

答案 0 :(得分:1)

theTextGotFromServer = "some text, then emoji code: \uD83D\uDE46\uD83C\uDFFE\uD83E\uDD16 some more text";
mTextView.setText(fromCardInfo); 

答案 1 :(得分:0)

使用.attr()函数(https://api.jquery.com/attr/)获取src属性的值。

喜欢这样

var audioSrc = $('#jp_audio_0').attr('src');

答案 2 :(得分:0)

您只需使用以下内容获取src元素的audio属性即可 -

$('#jquery_jplayer_1').find('audio').attr('src');

这是一个工作小提琴 - https://jsfiddle.net/2whaz67p/1/

答案 3 :(得分:0)

试试这个。

&#13;
&#13;
var src = $('#jp_audio_0').attr('src');
console.log(src);
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="jquery_jplayer_1" class="jp-jplayer" style="width: 0px; height: 0px;"><img id="jp_poster_0" style="width: 0px; height: 0px; display: none;"><audio id="jp_audio_0" preload="metadata" src="/system/songs/song_files/000/000/054/original/9_horwood_-_gotta_get_out_of_the_city.wav?1492962591" title="Gotta Get Out Of The City"></audio></div>
&#13;
&#13;
&#13;