jQuery 手机不通过 ID
jQuery mobile not going through ID
我正在制作一个音频应用程序。
当我点击播放按钮时,它的 id 应该动态更改 - 如 id = "paused".
然后点击它,它应该会暂停,但这是行不通的。
$('#pauses').click(function())
当我点击暂停按钮时,它仍然在播放。
您可以进行简单的更改以使其正常工作。更改您的 html 添加 data-status
<a data-role="button" data-status="play" data-theme="a" id="play" href="#">Play</a>
对于 JavaScript 代码,您可以这样做。
$('#play').click(function() {
if($(this).data('status') == "play") {
$(this).text("P A U S E");
$(this).data('status', 'pause');
doPlay();
} else {
$(this).text("P L A Y");
$(this).data('status', 'play');
doPause();
}
});
P.s:避免修改id
of elements
我正在制作一个音频应用程序。
当我点击播放按钮时,它的 id 应该动态更改 - 如 id = "paused".
然后点击它,它应该会暂停,但这是行不通的。
$('#pauses').click(function())
当我点击暂停按钮时,它仍然在播放。
您可以进行简单的更改以使其正常工作。更改您的 html 添加 data-status
<a data-role="button" data-status="play" data-theme="a" id="play" href="#">Play</a>
对于 JavaScript 代码,您可以这样做。
$('#play').click(function() {
if($(this).data('status') == "play") {
$(this).text("P A U S E");
$(this).data('status', 'pause');
doPlay();
} else {
$(this).text("P L A Y");
$(this).data('status', 'play');
doPause();
}
});
P.s:避免修改id
of elements