2016-05-30 28 views
1

我添加到我的ASP.NET項目中的一個html音頻播放器。我把它與jQuery分成了不同的類,我可以用CSS來設計它。 用於我使用的腳本調用。爲ASP.NET中的HTML類添加腳本

<script> 
     $(function() { $('audio').audioPlayer(); }); 
</script> 

但是,如果我在ASP.NET中使用它不起作用。

我將腳本添加到一個包中。

public class BundleConfig 
{ 
    public static void RegisterBundles(BundleCollection bundles) 
    { 

     bundles.Add(new ScriptBundle("~/bundles/audioplayer").Include(
        "~/Scripts/jquery-{version}.js", 
        "~/Scripts/audioplayer.js")); 
    } 
} 

而且我在底部添加了渲染腳本。

@section Scripts { 
@Scripts.Render("~/bundles/audioplayer") 
} 

現在,如果我調試的一面,他只顯示我的正常標記,沒有任何設計。他們不添加我的-tag功能。

也許有人發現我的錯或我忘了它會工作?

+0

添加@ Scripts.Render( 「〜/包/ audioplayer」)在該網站的頂部 –

+0

@DenisWessels是正確的,它的捆綁js的audioplayer必須在你的js代碼的頂部聲明.audioPlayer() –

+0

@DenisWessels他表明我仍然是正常的音頻元素,我測試th e腳本標記帶有警戒線,現在他使用腳本,但我認爲他在「$(function(){$('audio').audioPlayer(); })「line。 – JulianK

回答

0

我得到它的工作對我side.Please試試這個:

@{ 
    ViewBag.Title = "Home Page"; 
    Layout = null; 
} 

<link href="~/Content/audio.css" rel="stylesheet" /> 
<script src="https://code.jquery.com/jquery-1.12.2.min.js"></script> 
<script src="http://osvaldas.info/examples/audio-player-responsive-and-touch-friendly/audioplayer.js"></script> 

<script type="text/javascript"> 
    $(function() { 
     $('audio').audioPlayer(); 
    }); 
</script> 
<div style="width:300px;"> 
    <audio src="~/Music/song.mp3" preload="auto" controls autoplay loop></audio> 
</div> 

輸出:

audioplayer.js plugin

+0

我創建了一個新的空方,並添加了你的代碼,但它可以工作。 之後我嘗試做一個新的ASP.NET(MVC)項目並且再次添加代碼bt沒有任何結果。 – JulianK

+0

你有一個文件夾在你的名爲Music的應用程序中有一個名爲song.mp3的文件?將代碼從我的示例中複製到你的視圖中 –

+0

我適合我的代碼文件夾和css路徑 當我在普通html中使用腳本時,它工作正常。我使用瀏覽器devolper工具查找代碼,在ASP.NET中,我實際上看到了