变量后添加扩展名

时间:2012-07-01 22:13:56

标签: javascript customization attr file-extension

我在我的网站上使用了一些javascript用于某些音频:

<script type="text/javascript">
    $(function() {
        var a = audiojs.createAll({
            trackEnded: function() {
                var next = $("ul li.cow").next();
                if (!next.length) next = $("ul li").first();
                next.addClass("cow").siblings().removeClass("cow");
                audio.load($("a", next).attr("duck"));
                audio.play();
            }
        });
        var audio = a[0];
        first = $("ul a").attr("duck");
        $("ul li").first().addClass("cow");
        audio.load(first);
        $("ul li").click(function(e) {
            e.preventDefault();
            $(this).addClass("cow").siblings().removeClass("cow");
            audio.load($('a', this).attr('duck'));
            audio.play();
        });
    });
</script>

我想做的是在属性“duck”之后添加“.mp3”...我该怎么做? *属性“duck”出现三次,我想在所有三个之后添加扩展名“.mp3”:)

谢谢, 约什

2 个答案:

答案 0 :(得分:2)

要更改其属性:

$("ul a").each(function(){
    $(this).attr("duck", $(this).attr("duck") + ".mp3");
});

仅更改字符串:

first = $("ul a").attr("duck") + ".mp3";

答案 1 :(得分:0)

我猜你问的是简单的字符串添加?然后添加

+ ".mp3"
每次attr('duck')之后