在下面的代码中,单击播放按钮时其值应更改为暂停,单击暂停时应调用其他函数.如何使用
jquery切换执行此操作
- <input type="button" onclick ="play" value="play"/>
- <script>
- function play()
- {
- play_int();
- // Button value to be changed to pause
- }
- And when pause play_pause();
解决方法
给你的按钮一个ID:
- <input type="button" id="play" value="play"/>
然后你可以做这样的事情:
- $('#play').click(function() {
- if ($(this).val() == "play") {
- $(this).val("pause");
- play_int();
- }
- else {
- $(this).val("play");
- play_pause();
- }
- });
或者像这样的稍微整洁的版本:
- $(function(){
- $('#play').click(function() {
- // if the play button value is 'play',call the play function
- // otherwise call the pause function
- $(this).val() == "play" ? play_int() : play_pause();
- });
- });
- function play_int() {
- $('#play').val("pause");
- // do play
- }
- function play_pause() {
- $('#play').val("play");
- // do pause
- }