Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用jQuery使表单输入字段充当链接?_Javascript_Jquery_Forms - Fatal编程技术网

Javascript 如何使用jQuery使表单输入字段充当链接?

Javascript 如何使用jQuery使表单输入字段充当链接?,javascript,jquery,forms,Javascript,Jquery,Forms,我在一个页面上有一个表单,有两个文本字段和一个提交按钮。在短时间内,我想做的是使按钮和文本字段都像指向同一事物的链接。单击其中任何一个页面时,我希望出现一个“是/否”对话框,显示“维护中的表单。您被重定向到某个页面。是否继续?”否关闭,不执行任何操作,是将您发送到URL 这可能吗?如果是这样的话,如何使用vanilla js或jQuery实现呢?您可以将处理程序附加到所有这些输入字段上的单击事件。然后,您可以使用确认功能提示用户,并在用户选择“确定”时重定向用户 HTML: 您可以将处理程序附加

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


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

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

HTML:


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

HTML:


在jquery中,只需在输入端附加一个click事件监听器即可:


$(“#fred”)。在(“单击”,函数()上)
{
//可以在此处添加重定向到新页面的确认框
窗口警报(“钓鱼”);
});

在jquery中,只需在输入端附加一个click事件监听器即可:


$(“#fred”)。在(“单击”,函数()上)
{
//可以在此处添加重定向到新页面的确认框
窗口警报(“钓鱼”);
});
试试这个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
    }
});
请尝试以下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
    }
});

一开始向他们展示表格真的有理由吗?难道你不能直接重定向它们,或者只是有一个错误样式的类型页面吗?是否真的有理由首先向它们显示表单?你不能直接重定向它们,或者只是有一个错误样式的类型页面吗?或者只是在整个正文中添加一个单击,或者。。在整个窗体上放置一个不可见的div,或者在整个主体上单击鼠标,或者。。在整个窗体上放置一个不可见的div
<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");
});
$('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 = "/...";
     }
  }
});
$("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
    }
});