/点歌api:http://wx0725.top/project/php/jiqiren/xiaodie.php?keyword=点歌+歌名&type=json
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<audio src="" id='myaudio' controls>
<source src="song.ogg" type="audio/ogg">
<source src="song.mp3" type="audio/mpeg">
</audio>
<br>
<input type="text"id="ipt" placeholder="请输入歌名"/>
<button type="button" id="btn">点歌</button>
<script type="text/javascript">
var btn = document.querySelector('#btn');
var ipt = document.querySelector('#ipt');
btn.addEventListener('click',function(){
var xhr = new XMLHttpRequest();
xhr.open('get',"http://wx0725.top/project/php/jiqiren/xiaodie.php?keyword=点歌"+ipt.value+"&type=json");
xhr.send();
xhr.onload = function(){
var result = JSON.parse(xhr.responseText);
var myaudio = document.querySelector('#myaudio');
myaudio.src=result.mp3;
}
})
</script>
</body>
</html>
|