2011-07-11 60 views
1

如何更改JavaScript提示中按钮上的文字?我是新的,所以最简单的方式将不胜感激。更改JavaScript提醒按钮

+0

按钮?警告框内只有*一个*按钮... –

回答

6

你不能。

相反,您可以使用jQuery UI Dialog在DOM中创建一个假对话框。

+0

这是如何阻止JS执行的? – ShankarSangoli

+0

它不能。因此,您不应该更换内置的'alert'函数。 – SLaks

+0

我听到你Slaks,但没有提到有关这个问题。 – ShankarSangoli

3

不可能的,浏览器设置一个

你可以做的是使从元素假警报,

0

可以overriede window.alert,有自己的它实行。

window.alert = function(msg, options){ 
    //Create the alert dialog box here using the default options and show the message. 
} 

你不必改变使用它的应用程序代码。

+0

这是不正确的。 'alert'是一个阻塞呼叫;没有办法来模拟。 – SLaks

+0

您可以创建一个模式对话框,这将肯定会阻止页面上的用户界面。 – ShankarSangoli

+0

但它会立即返回。 'alert'只在用户点击OK时才会返回。 – SLaks

0

尝试这样的事情

function CustomAlert(msg){ 
var customAlert = $("#customAlert"); 
     if(!customAlert.length){ 
     customAlert = $(document.body).append('<div id="customAlert"><div class="message">Msg></div><div><input class="button"  type="button" value="Ok" /></div></div>').hide(); 
} 
customAlert.find("message").html(msg); 

//Code to center the customAlert into view port along with faded background will go here 

customAlert.find("input.button").unbind("click").click(function(){ 
//Hide the customAlert goes here 
customAlert.hide(); 
}); 

    } 
+0

正如我一直试图解释的,**此函数将立即返回**,在用户单击确定之前。为了理解我的意思,请连续调用两次。 – SLaks

+0

该函数将立即返回,但现在您显示了警告消息,该消息是abosolute定位的div容器,并且还阻止了UI。除非用户点击确定,否则不会解除阻止。 – ShankarSangoli

+0

**但您的代码将继续运行**。这是一个突破性的改变,所以你不应该取代'alert'。 – SLaks