开发者

Impromptu plugin for Alert Boxes

When we use Javascript prompt Box something like this

 var ur_name = prompt("Enter Name");

We will have two types of values in this case:

  1. Value entered by user.
  2. Second VALUE can be NULL, when user press CANCEL or When he presses ESCAPE Key. Right...!

Now The problem I'm facing is: HOW to Handle escape key in Impromptu plugin of Jquery link text

Code running perfectly When user will enter some value OR press Cancel button

<script type='text/javascript'>
function test()
 {
var txt = 'Please enter your name:<br /> <input type="text" id="alertName" name="alertName" value="name here" />';

 $.prompt(txt,{
callback: mycallbackform,
buttons: { OK: 'Hello', Cancel: 'Good Bye' }
  });
}

 function mycallbackform(v,m,f){
  if(v=="Hello")     
   $.prompt("Stack Over flow User:"+' ' + f.alertName);
  }
 </script>

Cause in this scenario I'm getting cancel 开发者_Python百科or OK button key pressed events, but when user press ESCAPE key mycallbackform will not be called...


In the past I have always used the jQueryUI .dialog function to provide user dialogs which has the closeOnEscape option. (http://jqueryui.com/demos/dialog/)

If you have your heart set on using impromptu it should be fairly easy to implement some event handling using the jQuery function keyup -

$(document).keyup(function(event){
    if (event.keyCode == 27) {
        $(".prompt").hide();
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜