第二次点击jQuery不起作用 - 移动 [英] jQuery on second click doesn't work - mobile

查看:433
本文介绍了第二次点击jQuery不起作用 - 移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在你说其他主题重复之前,我已经看到了这些主题,例如:

jQuery:trigger click()不起作用?

jQuery .on点击第二次不工作



Jquery Onclick第二次没有发生



一个Jquery不是在第二次点击上工作



没有一个帮助我。
我的代码非常简单:

index.php

  / * in body tag * / 

$ b $ * / body标签* /
$(function(){
$(#page-add)。click(function(e){
window.location.href ='add.php';
});
});

add.php

正文标记中的 / * * / 
< div class =ui-btn-left>< a href =index.php>< img src =images /logo.png\"/></a></div>

按钮page-addonClick事件当我点击< a href> 并且它回到index.php时,如果再次点击同一个按钮,它不会不再工作了。我必须刷新页面才能重新运行。



我试图在之前添加window.location.href 代码 e.preventDefault()但也无效。我在控制台上没有收到任何错误。



我做错了什么?



编辑:已解决。

  $(document).on('pagebeforeshow','#main',function(){
$('#page-add')。bind('click',function(){
$。 mobile.changePage('add.php');
});
});


解决方案

尝试使用jQuery函数,

  $(element).on(click,function(){
alert(clicked);
});


Before you say that is duplicate from other topics, I've seen that topics, such as:

jQuery: trigger click() doesn't work?

jQuery .on Click second time not working

Jquery Onclick not happening second time

one Jquery is not working on the second click

And none of that help me. My code is very simple:

index.php

/* in body tag */

<input type="button" id="page-add" value="Add" data-role="none"/>

/* after body tag */
$(function(){
    $("#page-add").click(function(e){
        window.location.href = 'add.php';   
    });
});

add.php

/* in body tag */
<div class="ui-btn-left"><a href="index.php"><img src="images/logo.png"/></a></div>

The button "page-add" onClick event works for the first time, when I click the <a href> and it backs to the index.php, if I click again on the same button it doesn't work no more. I've to refresh the page so it can work again.

I've tried to add before the window.location.href the code e.preventDefault() but didn't work either. I don't receive any errors on console.

What am I doing wrong?

Edit: Solved.

$(document).on('pagebeforeshow', '#main', function(){     
    $('#page-add').bind('click',function(){
        $.mobile.changePage('add.php');
    });
});

解决方案

Try jQuery on function for the same,

$( "element" ).on( "click", function() {
alert("clicked");
});

这篇关于第二次点击jQuery不起作用 - 移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆