如何用jquery对话框替换JavaScript警报(弹出事件调用它的位置)? [英] How to replace javascript alert (which pops up where the event called it) with a jquery dialog box?

查看:76
本文介绍了如何用jquery对话框替换JavaScript警报(弹出事件调用它的位置)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,我打算把它分解得更清楚些。当我看着那些JQuery UI的东西时,我对我需要下载什么以及在哪里放置这些文件感到困惑。



我做得很成功的是链接到JQuery网站,这样我就不必下载任何内容,并看到对话框可以正常工作。



但是,从示例中显示的对话框链接到div。如果div位于屏幕的顶部并且输入框位于底部,那么div无法帮助我。从头文件中只有一个函数是从多个文本框中调用的。这个函数包含一个javascript alert()和一个消息。



请告诉我需要输入的EXACT代码(我们称之为MyFunction() ),无论MyFunction被调用,它都会弹出消息。



如果是javascript,在脚本的头部我们会有:

 < script type =text / javascript> 

函数digitsOnly(){
alert(仅数字,请);
}

< / script>

在很多文本框中,我们都有:

 < input type =test / javascriptonkeydown =digitsOnly()/> 

我需要一个漂亮的弹出框来替换javascript alert();
除了在调用文本框旁边弹出消息之外,我不需要做任何其他操作。如果它可以拖动和调整大小,那将是最酷的事情。但现在,我会很满意我提到的。



我一直在学习语言。我知道我最终也会学习JQuery。但是如果可能的话,我今晚也需要这样做。

Javascript的 alert()函数在其他任何东西之前运行,所以很难(如果不是不可能的话)实际替换它的默认行为。但是,您可以轻松地创建自己的功能。而不是:

  $('。clickable')。click(function(){
alert(Clicked。 );
});

执行此操作:

  $('。clickable')。click(function(){
$('。dialog')。dialog({
// options ...
} );
});

您必须仔细检查您的代码,并用此代替每个警报,但是,不应该太大了,特别是如果你使用的是类似Textmate的软件,它有一个搜索项目功能。


Fellows, I'm going to break it down a little clearer. When I look at that JQuery UI stuff, I get absolutely confused as to what I need to download and where to put the files.

What I DID just do successfully was to link to the JQuery website so that I didn't have to download anything and saw that the dialog box works.

However, the dialog box, from the example shown me, is linked to a div. That div is not going to help me if it's at the top of the screen and the input box is at the bottom. I have only one function in the header that is called from a number of textboxes. This function includes a javascript alert() with a message.

PLEASE, tell me the EXACT code I need to type in the function (We'll call it MyFunction() ) that will pop up a message wherever the MyFunction is being envoked..

If it was javascript, in the head section in a script we'd have:

<script type="text/javascript">

function digitsOnly(){
alert("Digits only, please");
}

</script>

and in a number of textboxes, we'd have:

<input type="test/javascript" onkeydown="digitsOnly()" />

I need a beautiful pop-up box to replace the javascript alert(); I don't need this do do anything other than pop up a message next to the calling textbox. If it's draggable and resizable, that would be the coolest thing. But for now, I'll be happy with what I mentioned..

I study languages all the time. I know I'll eventually learn JQuery too. But I need this done tonight if possible.

James

解决方案

Javascript's alert() function runs before anything else, so it's hard (if not impossible) to actually replace its default behavior. However, you can easily make your own function. Instead of:

$('.clickable').click(function() {
  alert("Clicked.");
});

Do this:

$('.clickable').click(function() {
  $('.dialog').dialog({ 
    // options...
  });
});

You will have to go through your code and replace each alert with this, however, that shouldn't be too big of a deal, especially if you're using something like Textmate, which has a "Search Project" feature.

这篇关于如何用jquery对话框替换JavaScript警报(弹出事件调用它的位置)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆