jQuery mobile not going through ID

jQuery mobile not going through ID

本文关键字:through ID going not mobile jQuery      更新时间:2023-09-26

我正在制作一个音频应用程序
当我点击播放按钮时,它的id应该动态更改,就像id="paused"一样
然后点击它,它应该会暂停,但这不起作用。

$('#pauses').click(function())

当我点击暂停按钮时,它仍然在播放。

请看一下例子:https://jsfiddle.net/shivam_sh/4zL4en10/2/

您可以进行简单的更改以使其工作。更改您的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();
  }  
});

jsfiddle链接此处

p.s:避免对elementsid进行修改