2012-01-20 8 views
0

私はダイアログボックスを持っており、その中には2つのボタンがあり、1つは継続し、もう1つはキャンセルします。なぜ私のダイアログボックスは一度だけ動作しますか?

$(document).ready(function(){ 
$("[name=resetPwd]").click(function(){ 
    var id = $(this).attr("userid"); 
    var email = $("[field=emailAddress].[userid="+id+"]").text(); 
    var name = $("[field=firstName].[userid="+id+"]").text(); 

    var message = $('<div></div>') 
    .html('You are about to reset the password for:<br/>'+name+'.<br/>This will send an e-mail to:<br/>'+ 
      email+'<br/><br/><input id="_continue" type="button" value="Continue" /> <input id="_cancel" type="button" value="Cancel" />') 
    .dialog({ 
     title: 'Reset Password' 
    }); 

    message.dialog('open'); 


    $("#_cancel").click(function(){ 
     message.dialog('close'); 
    }); 

}); 

それだけで正常に動作し、(1回目)のすべての私のデータがある、私はキャンセルし、それは閉じますが、私は再びdoesntのをキャンセルしようとすると、もう何かをクリックしたとき。誰かが間違って何をしているか知っている? pleaseとthanks

答えて

0

resetPwd要素をクリックするたびに、新しいダイアログオブジェクトを作成しています。

クリックハンドラーの外にダイアログを作成し、オープンメソッドとクローズメソッドを使用して参照するだけです。

+0

クリックハンドラの外にダイアログを作成すると、すべてのページで自動的に開きます。私はこの1ページの作業にしか使えない方法がありますか? – Dagron

+0

これは働いてくれてありがとう – Dagron

+0

よろしくお願いします。あなたがうまく働いてうれしい。 – BZink

1

$("[name=resetPwd]").click体機能のうち$("#_cancel").clickを移動してみてください。また、$(document).ready関数を正しく終了していません。 ID =メッセージで空のdivを作成し、更新されたコードを試してみてください。

$(document).ready(function(){ 
    $("[name=resetPwd]").click(function(){ 
     var id = $(this).attr("userid"); 
     var email = $("[field=emailAddress].[userid="+id+"]").text(); 
     var name = $("[field=firstName].[userid="+id+"]").text(); 

     var message = $('#message') 
     .html('You are about to reset the password for:<br/>'+name+'.<br/>This will send an e-mail to:<br/>'+ 
       email+'<br/><br/><input id="_continue" type="button" value="Continue" /> <input id="_cancel" type="button" value="Cancel" />') 
     .dialog({ 
      title: 'Reset Password' 
     }); 

     message.dialog('open'); 
    }); 
    $("#_cancel").click(function(){ 
     $('#message').dialog('close'); 
    }); 
}); 

EDITを:

これを試してみてください。

+0

私はボタンが作られる前にキャンセルクリックハンドラを持っていればハンドラはそれを見つけられないと思う..これは本当ですか?私はこれがボタンがちょうどdoesnt仕事...なぜ私が現在の2つの答えのミックスをするべきであるかと思いますか? – Dagron

関連する問題