加林森 发表于 2022-2-12 20:44

马黑黑 发表于 2022-2-12 20:17
你查看你源码中和这个截图相近的部分,看看是不是中括号里的 i 连同中括号被吞掉了:

<style type="text/css">

#waiDiv { margin:10px auto; padding:8px; width:400px; background:tan; border-radius:10px; box-shadow:2px 2px 4px #000; display:flex; flex-direction:column; position:relative; }
#audDiv { width:100%; display:flex; flex-direction:row; align-items:center; gap:8px; }
#audDiv audio { width:360px; height:30px; }
#audDiv div { margin:6px; background:#eee; text-align:center; width:30px; height:30px; line-height:30px; border-radius:50%; cursor:pointer; }
#mLiDiv { background:#eee; color:#000; min-height:100px; padding:10px; border:1px solid olive; }
#mLiDiv a { cursor:pointer; text-decoration: none; }
#prompt { position:absolute; left:200px; top:50px; width:400px; padding:6px 12px; background:silver; font-size:12px; display:none; box-shadow:1px 1px 1px #666; border-radius:2px; }
#prompt input { outline:none; }
#prompt input { margin:4px;padding:4px; width:392px; }
#prompt input { border-radius:4px; cursor:pointer;border:1px solid gray; border-radius:3px; box-shadow: 1px 1px 2px #444; }
#prompt input { cursor:pointer; }

</style>

<div id="waiDiv">
      <div id="audDiv">
                <audio id="myPlayer" controls="controls" loop="loop"></audio>
                <div id="add1">+</div>
      </div>
      <div id="mLiDiv"></div>
      <div id="prompt">
      <div>添歌&设置</div>
                <input type="text" id="mName" placeholder="歌曲名称" /><br />
                <input type="text" id="mUrl" placeholder="歌曲地址" /><br /><br />
                <div style="text-align:center;">
                        <input id="subMe" type="button" value="添加" />
                        <input id="cancelMe" type="button" value="算了" />
                        <input id="dqxh" type="radio" name="rad" checked="checked" />单曲循环
                        <input id="lhbf" type="radio" name="rad" />轮回播放
                </div>
      </div>
</div>

<script language="javascript">

var aud = document.getElementById('myPlayer');
var mLi = document.getElementById('mLiDiv');
var mAdd = document.getElementById('add1');
var prom = document.getElementById('prompt');
var cancelMe = document.getElementById('cancelMe');
var subMe = document.getElementById('subMe');
var dqxh = document.getElementById('dqxh');
var lhbf = document.getElementById('lhbf');
var muAr = [
      ["https://www.joy127.com/url/88626.mp3","潇洒的走"],
      ["https://www.joy127.com/url/88624.mp3","古城新韵"],
      ["https://www.joy127.com/url/88615.mp3","别让我一个人醉"],
      ["https://www.joy127.com/url/88613.mp3","闹元宵"],
      ["https://www.joy127.com/url/88618.mp3","迷宫"],
      ["https://www.joy127.com/url/88617.mp3","爱到底怎么了"],
      ["https://www.joy127.com/url/88616.mp3","爱的天堂"],
      ["https://www.joy127.com/url/88623.mp3","未结的果"]
];
var playIdx = 0;
var str = "";



for(i=0; i<muAr.length; i++) {      str += (i+1) + ".<a id='list" + i + "' onclick='iPlay(" + i + ")' >" + muAr + "</a><br />";}↓

mLi.innerHTML += str;

function iPlay(idx){
      playIdx = idx;
      aud.src = muAr;
      aud.play();
      nameRed(playIdx);
}

mAdd.onclick = function(){
      prom.style.display = "block";
}

cancelMe.onclick = function(){
      prom.style.display = "none";
}

subMe.onclick = function(){
      let uri = document.getElementById('mUrl');
      let name = document.getElementById('mName');
      let tnum = muAr.length;
      let str1 = uri.value;
      let str2 = name.value;
      if(str1 !="" && str2 != ""){
                muAr = ;
                mLi.innerHTML += (tnum+1) + ".<a id='list" + tnum + "' onclick='iPlay(" + tnum + ")' >" + str2 + "</a><br />";
                iPlay(tnum);
                uri.value = "";
                name.value = "";
      }
      prom.style.display = "none";
}

function howplay(){
      dqxh.checked ? aud.loop = true :(aud.loop = false,playNext(),aud.addEventListener('ended',playNext,false));
      prom.style.display = "none";
}
function playNext(){
      iPlay(playIdx);
      playIdx += 1;
      if(playIdx >= muAr.length) playIdx = 0;
}

function nameRed(){
      for(i=0;i<muAr.length;i++){
                let listId = "list" + i;
                document.getElementById(listId).style.color = "black";
      }
      listId = "list" + playIdx;
      document.getElementById(listId).style.color = "red";
}

</script>

加林森 发表于 2022-2-12 20:45

老黑帮着看看,我修改过来了。

马黑黑 发表于 2022-2-12 20:49

加林森 发表于 2022-2-12 20:45
老黑帮着看看,我修改过来了。

你放出的代码还是中括号里的i连同中括号被转变为了斜体字体。当然,也许你的帖子发对了。

马黑黑 发表于 2022-2-12 20:50

加林森 发表于 2022-2-12 20:31
for(i=0; i

还不成功么

加林森 发表于 2022-2-12 20:51

马黑黑 发表于 2022-2-12 20:50
还不成功么

还是不出来,不知道是怎么会事情了?

马黑黑 发表于 2022-2-12 20:53

加林森 发表于 2022-2-12 20:51
还是不出来,不知道是怎么会事情了?

就是你在发帖时代码被吞噬。你要在本地先测试,好了后,到论坛一次性发出,不要切换、不要修改。

加林森 发表于 2022-2-12 20:54

马黑黑 发表于 2022-2-12 20:49
你放出的代码还是中括号里的i连同中括号被转变为了斜体字体。当然,也许你的帖子发对了。

怎么回事?晕!

加林森 发表于 2022-2-12 20:55

马黑黑 发表于 2022-2-12 20:53
就是你在发帖时代码被吞噬。你要在本地先测试,好了后,到论坛一次性发出,不要切换、不要修改。

好的好的,我再去试一试。

马黑黑 发表于 2022-2-12 20:56

加林森 发表于 2022-2-12 20:54
怎么回事?晕!

原理是:论坛支持中括号代码,恰好 [ i ] (中间没有空格)是论坛要用的,而JS数组代码中又得有这个东东,被论坛解析为了斜体字体设定

马黑黑 发表于 2022-2-12 20:57

加林森 发表于 2022-2-12 20:54
怎么回事?晕!

你可以尝试在JS中有 [ i ] 的给 i 前后加空格

加林森 发表于 2022-2-12 21:00

马黑黑 发表于 2022-2-12 20:57
你可以尝试在JS中有 [ i ] 的给 i 前后加空格

好的好的,我发出来,你去看看。
页: 1 2 [3]
查看完整版本: 测试 audio 播放器