php - Onclick 返回确认在 Jquery Mobile 中不起作用?

标签 php javascript jquery html jquery-mobile

我正在使用简单的 javascript 确认代码:

function test_confirm (str)
{
    str = (str == '0')? 'Are you sure?' : str

    return (confirm(str))? true : false
}

<a href="http://example.com" onclick="return test_confirm(0)">Test</a>

这通常有效,除非我使用 Jquery Mobile OKCancel按钮都会转到 URL。预期的行为是Cancel按钮不应继续访问该 URL。

即,我通过在 html head 中添加以下内容来使用 Jquery Mobile :

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>

制作 javascript confirm() 有什么我应该注意的吗?函数在 Jquery Mobile 中工作吗?

<小时/>

菲尔·帕福德更新:

它确实可以在纯 HTML 上工作,但这实际上是我正在做的事情,并且在使用 PHP 的 header('location:') 重定向到同一页面后它不起作用:

页面list包含:

<a href="list/delete/1" class="customClick" data-str="0">Delete 1</a>

<a href="list/delete/2" class="customClick" data-str="0">Delete 2</a>

list/delete操作包含如下内容:

$rest->delete($id);
header('location: http://example.com/list');

点击 URL list/delete/1 后可以看到删除过程将继续,然后重定向回 list页。这就是它开始不起作用的地方。

一旦发生重定向,确认对话框就不再起作用。

最佳答案

这样的东西对你有用吗?

JS

$('.customClick').on('click', function() {
    var str = $(this).attr('data-str');
    str = (str == '0')? 'Are you sure?' : str;

    return (confirm(str))? true : false;
});

HTML

<a href="http://jsfiddle.net/8CDc5/" class="customClick" data-str="0">Test</a>​

关于php - Onclick 返回确认在 Jquery Mobile 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13277910/

相关文章:

javascript - 使用javascript的Strapi日期格式

javascript - 在外部单击时关闭弹出窗口(正文)

php - HHVM-FastCGI : poor performance

javascript - 尝试将 php 变量传递给 js

php - 加载脚本时在 SSH2_EXEC 之后停止页面加载

javascript - 如何使用 ng-checked 和 ng-model 选择全部

svg - 使用 Snap.svg 选择多个路径

jquery - 克隆的关闭按钮无法正常工作

javascript - 在 JS 或 jQuery 或任何客户端脚本的帮助下通过查看源代码阅读源代码

php - 通过 PHP 查看 MySQL 数据库流量