为什么这不起作用(javascript + 音频播放器)
我正在尝试在我的网站上使用 JavaScript 音频播放器(http://wpaudioplayer.com/standalone/)。我尝试将 PHP 变量传递到 JavaScript,但它似乎无法正常工作。 JavaScript 将 html 段落替换为匹配的 id 到 flash mp3 播放器中。
编辑:更新了问题
如果我直接传递 url,mp3 播放器会播放,但当我通过变量传递它时,它不会播放。
这有效
<p id="audioplayer_<?php echo $i ?>">Install flash to use mp3 player</p>
<script type="text/javascript">
var id = "audioplayer_" + <?php echo $i ?>;
AudioPlayer.embed(id, {soundFile: "http://site.com/mp3file.mp3"});
</script>
但这不起作用
<p id="audioplayer_<?php echo $i ?>">Install flash to use mp3 player</p>
<script type="text/javascript">
var id = "audioplayer_" + <?php echo $i ?>;
var url = "<?php echo $url ?>";
AudioPlayer.embed(id, {soundFile: url});
</script>
$url 变量的值为 http://site.com/mp3file.mp3
I am trying to use the JavaScript audio player(http://wpaudioplayer.com/standalone/) on my website. I tried passing PHP variables into the JavaScript but it does not seem to work properly. The JavaScript replaces the html paragraph with a matching id into a flash mp3 player.
EDIT: Updated the issue
If I pass the url directly, the mp3 player plays but when I pass it through a variable it does not.
This works
<p id="audioplayer_<?php echo $i ?>">Install flash to use mp3 player</p>
<script type="text/javascript">
var id = "audioplayer_" + <?php echo $i ?>;
AudioPlayer.embed(id, {soundFile: "http://site.com/mp3file.mp3"});
</script>
But this does not
<p id="audioplayer_<?php echo $i ?>">Install flash to use mp3 player</p>
<script type="text/javascript">
var id = "audioplayer_" + <?php echo $i ?>;
var url = "<?php echo $url ?>";
AudioPlayer.embed(id, {soundFile: url});
</script>
The value of the $url variable is http://site.com/mp3file.mp3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您忘记在 url 两边加上引号,因为对于 JavaScript 来说它是一个字符串。将您的 PHP 代码更改为
You forgot to put quotes around the url, because to JavaScript it is a string. Change your PHP code to
如果您在任何其他地方不需要变量,请不要使用它们并尝试
使用此代码,以避免“变量问题”
If you do not need the variables at any other place, don't use them and try this
with this code you avoid "variable issues"