0

2つのテキストフィールドと送信ボタンがあるページにフォームがあります。少しの間、ボタンとテキストフィールドがすべて同じものへのリンクのように機能するようにしたいのです。それらのいずれかをクリックすると、「フォームはメンテナンス中です。そのようなページにリダイレクトされます。続行しますか?」という「はい/いいえ」ダイアログを表示したいと思います。いいえは閉じて何もしません。はいはあなたをURLに送ります。

これは可能ですか?もしそうなら、それはバニラjsまたはjQueryでどのように達成できますか?

4

4 に答える 4

4

これらすべての入力フィールドのクリック イベントにハンドラーをアタッチできます。次に、確認機能を使用してユーザーにプロンプ​​トを表示し、ユーザーが「OK」を選択した場合にユーザーをリダイレクトできます。

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 に答える