0

我在页面上有一个带有两个文本字段和一个提交按钮的表单。在短时间内,我想做的是使按钮和文本字段都像指向同一事物的链接一样。单击其中任何一个时,我希望出现一个是/否对话框,显示“正在维护的表单。您将被重定向到某个页面。继续吗?” No 关闭并且什么也不做, Yes 将您发送到 URL。

这可能吗?如果是这样,如何使用 vanilla js 或 jQuery 来实现?

4

4 回答 4

4

您可以将处理程序附加到所有这些输入字段上的单击事件。然后,您可以使用确认功能来提示用户并在用户选择“确定”时重定向用户。

HTML:

<input type="text" />
<input type="text" />
<input type="submit" />

jQuery:

   $("input").click(function(){
       if(window.confirm("Form under maintenance. You're being redirected to such and such page. Proceed?")){
           location.href = "http://example.com/temp_page";
       }
    });
于 2013-02-14T02:12:08.880 回答
0

在 jquery 中,您只需在输入上附加一个单击事件侦听器即可:http: //jsfiddle.net/CuWHH/

<input type='text' id='fred' value='none'>
$("#fred").on("click",function()
{
   //can add a confirm box that redirects to new page here
   window.alert("going fishing");
});
于 2013-02-14T02:12:29.533 回答
0
$('input[type=submit], input[type=text]').click(function() {
    var r=confirm("Form under maintenance. You're being redirected to such and such page. Proceed?");
    if (r==true)
     {
        window.location = "/...";
     }
  }
});
于 2013-02-14T02:13:03.743 回答
0

试试这个 jQuery 代码:

$("button, input").click(function(e){
    e.preventDefault(); //Stops the default action of an element from happening
    if(confirm("Form under maintenance. You're being redirected to such and such page. Proceed?")) {
        location.href = "http://www.google.com"; //Change it to your URL
    }
});
于 2013-02-14T02:14:04.897 回答