Py学习  »  Jquery

将echo php添加到jquery windows confirm()

GT73 • 4 年前 • 325 次点击  

在发送提交表单之前,我需要查看一条简单的确认消息。

我有一个包含要在弹出窗口中打印的值的变量。

如何在窗口中插入回音 确认() 是吗?

$('#mess').submit(function() {
    var conf = confirm("you are sent the message to<?php echo $count; ?>customer, Do you want to send?");
    return conf;
});
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/46532
 
325 次点击  
文章 [ 2 ]  |  最新文章 4 年前
Em Jay
Reply   •   1 楼
Em Jay    5 年前

我是这样做的,但是您可以使用submit handler并执行如下操作:

$('#yourFormButton').click(function(e) { e.PreventDefault() } 

“提交”按钮的默认操作是提交表单,因此需要停止该操作。

另一种选择和我使用的方式是,表单上的按钮应为“button”类型,而不是“submit”,然后使用以下选项:

$('#yourFormButton').click(function()
{ 
    var conf = confirm("you are sent the message to<?php echo $count; ?>customer, Do you want to send?");

    if(conf){
        $('#mess').submit();
    }
});
treyBake
Reply   •   2 楼
treyBake    4 年前

避免混合使用php和javascript是更好的做法。原因是php在 服务器 而javascript通过 浏览器 是的。把两者混合起来可能会导致一些意想不到的行为。

更可取的方法是 data-* 属性到dom元素。可以通过 .attr() 方法jquery有。

下面是如何使用的示例:

HTML/PHP格式:

<div id="jsInfo" data-count="<?php echo $count; ?>"></div>

JS公司:

$('#mess').submit(function()
{
    return confirm(
        'you are sent the message to'+ 
        $('#jsInfo').attr('data-count') +
        'customer, Do you want to send?'
    )
});