为什么这不起作用(javascript + 音频播放器)

发布于 2024-10-29 04:26:09 字数 1106 浏览 1 评论 0原文

我正在尝试在我的网站上使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空气里的味道 2024-11-05 04:26:09

您忘记在 url 两边加上引号,因为对于 JavaScript 来说它是一个字符串。将您的 PHP 代码更改为

<p id="audioplayer_<?php echo $i ?>">Install flash to use mp3 player</p>
        <script type="text/javascript">  
        var i = <?php echo $i ?>;
        var url = "<?php echo $url ?>";
    AudioPlayer.embed("audioplayer_" + i, {soundFile: url});  
    </script> 

You forgot to put quotes around the url, because to JavaScript it is a string. Change your PHP code to

<p id="audioplayer_<?php echo $i ?>">Install flash to use mp3 player</p>
        <script type="text/javascript">  
        var i = <?php echo $i ?>;
        var url = "<?php echo $url ?>";
    AudioPlayer.embed("audioplayer_" + i, {soundFile: url});  
    </script> 
血之狂魔 2024-11-05 04:26:09

如果您在任何其他地方不需要变量,请不要使用它们并尝试

<p id="audioplayer_<?php echo $i ?>">Install flash to use mp3 player</p>
<script type="text/javascript">  
AudioPlayer.embed("audioplayer_<?php echo $i; ?>", {soundFile: "<?php echo $url; ?>"});  
</script>

使用此代码,以避免“变量问题”

If you do not need the variables at any other place, don't use them and try this

<p id="audioplayer_<?php echo $i ?>">Install flash to use mp3 player</p>
<script type="text/javascript">  
AudioPlayer.embed("audioplayer_<?php echo $i; ?>", {soundFile: "<?php echo $url; ?>"});  
</script>

with this code you avoid "variable issues"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文