【发布时间】:2018-06-30 01:25:09
【问题描述】:
我正在使用 MVC 5 和 Razor 前端。当我第一次单击任何按钮时,它不会播放。它将在第二次单击时播放。我在代码末尾尝试了 .off ,但它没有用。我希望它在第一次单击按钮时播放,然后关闭。现在只需点击两次按钮即可启动轨道并正常运行其他轨道。
function play() {
//$(".song").unbind().click(function () {
$(".song").off('click').on('click', function () {
//this is the url
var url = $(this).attr("data-song");
var audio = $("#myAudio")[0];
if (audio.paused) {
audio.src = url;
audio.play();
} else {
audio.pause();
audio.currentTime = 0;
}
});
这是我的 HTML:
<table class="table" id="trackTable">
<tr>
<th>
</th>
<th>
@Html.DisplayNameFor(model => model.Title)
</th>
<th>
@Html.DisplayNameFor(model => model.Genre)
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td class="songRow">
<a href="#" class="song" data-song="@Url.Content(item.Path)" onclick="play()" ><img src="~/Images/playpause.png" alt="playpause" id="playbutton" /></a>
</td>
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
<td>
@Html.DisplayFor(modelItem => item.Genre)
</td>
<td></td>
</tr>
}
【问题讨论】:
标签: jquery asp.net-mvc razor