简体   繁体   English

更改jscript中的警报名称

[英]Change name of alert in jscript

Is there a way to change the name of a alert dialog box in jscript, like instead of it saying ("Alert" "Message") can it say something like ("Hello" "Message") this is the script im using: 有没有一种方法可以更改jscript中的警报对话框的名称,就像它不是说("Alert" "Message")而是说("Hello" "Message")这是脚本im使用:

<a href="#" onclick="alert('message');return false;">Click Here</a>

Thanks :D 感谢:D

If you want to alias alert it would be: 如果要使用别名alert ,它将为:

var t = alert;
t('blah');

If you want to change the text of the alert box's title bar, you can not. 如果要更改警报框标题栏的文本,则不能。

The best way to implement an alert with a custom title, would be to implement a custom dialog. 实施带有自定义标题的警报的最佳方法是实施自定义对话框。 You may want to look in to using jQuery UI Dialogs . 您可能需要使用jQuery UI对话框 There are many other implementations of custom Dialog controls. 自定义对话框控件还有许多其他实现。 Such as SimpleModal Dialog . SimpleModal对话框

Not as far as I am aware with the default basic Javascript alert() dialog box. 据我所知,默认的基本Javascript alert()对话框不大。

In fact, different browsers will have different title bars on the dialog. 实际上,不同的浏览器在对话框上将具有不同的标题栏。 Some have "Alert", others have "The page at http://someurl.com says:" and it goes on. 有些带有“警报”,有些带有“ http://someurl.com上的页面说:”,然后它继续。

A far prettier, and more customisable option is to consider using something like jQuery UI . 一个更漂亮,更可定制的选项是考虑使用jQuery UI之类的东西。 It has features like the dialog , which create a nicer, in-page dialog box with customisable buttons, title, and content. 它具有对话框之类的功能,该对话框可创建一个更好的页面内对话框 ,其中包含可自定义的按钮,标题和内容。

It requires use of the jQuery library, which is a hugely popular Javascript library to greatly ease Javascript development, and plainly, make it more fun . 它需要使用jQuery库,该库是一种非常流行的Javascript库,可以极大地简化Javascript的开发,并且显然可以使其更加有趣

The short answer is: no. 最简洁的答案是不。

However, alert is a host method and browsers can chose to implement it however they like. 但是, 警报是一种宿主方法,浏览器可以根据需要选择实现它。 But all browsers currently do not let script modify the standard alert dialogue. 但是当前所有浏览器都不允许脚本修改标准警报对话框。 You can create your own alert dialogue though using a suitably styled and positioned element. 您可以使用适当样式和位置的元素来创建自己的警报对话框。

If you mean function renaming 如果您的意思是功能重命名

<script type="text/javascript">
function hello(msg){
    alert(msg);
}
</script>
<a href="#" onclick="hello('message');return false;">Click Here</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM