dongyi8416 2017-04-11 03:59
浏览 238

如何从文本文件中动态更改src?

I have to change the src of an audio tag dynamically depends of a text file that I've got. I'm using HTML + PHP + MySQL. No JS, jQuery, or other things yet (because I don't know). The text file is generated with a Python script, so i have to read the content and put it in the src path.

Example:

Content of file.txt: 123456789
Final HTML code that i need:

<source src="../file_123456789.wav" type="audio/wav">

How can I read a file and use it as a string/variable to put in HTML? I'm thinking open the file with PHP and do an 'echo $content;' inside the src path but I think that there are better ways to do that.

Regards,

</div>
  • 写回答

2条回答 默认 最新

  • douhu2890 2017-04-11 04:18
    关注

    It would be much easier if you use JS/JQuery and you can find answer to this question. However, if you don't want to use JS/JQuery reading file and echoing it is the only method. If you are willing to use JQuery this will work. Find a Jquery CDN and link it in your HTML. Then:

    <script>
    $.get("file.txt", function(result){
       var scr = document.createElement('source');
       scr.type = 'audio/wav';
       scr.src = '../file_' + result + '.wav';
       document.body.appendChild(scr);
       });
     </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序