我可以添加一个和链接到javascript警报吗?

时间:2021-11-16 03:39:37

I have the following statement:

我有以下声明:

btnApply.Attributes.Add("onclick", "alert('Must be a member to Use this Tool')");

Is there a way to add a new line. I tried, but it showed the in the text. In addition, can I add a link that would close the alert and take the user to another page?

有没有办法添加新行。我试过,但它在文中显示了。此外,我可以添加一个链接来关闭警报并将用户带到另一个页面吗?

How can I do this with my example?

我怎么能用我的例子呢?

When I added the \n, the alert doesn't show up.

当我添加\ n时,警报不会显示。

10 个解决方案

#1


51  

You can't use HTML, but you can add line breaks:

您不能使用HTML,但可以添加换行符:

alert('line1\nline2');

If a rich modal popup is really what you want though, you can use jQuery's dialog feature and put whatever you want in there.

如果你想要的是丰富的模态弹出窗口,你可以使用jQuery的对话框功能并在那里放置任何你想要的东西。

#2


14  

Use \\n (needs two slashes).

使用\\ n(需要两个斜杠)。

You'll notice that before doing this the alert will not post even a javascript error. \n will not work because the slash needs to be escaped.

您会注意到,在执行此操作之前,警报甚至不会发布javascript错误。 \ n将无法工作,因为需要转义斜杠。

#3


4  

You cannot allow links but you can have newlines.

您不能允许链接,但可以使用换行符。

Just use "\n" for a newline instead of <br/>.

只需使用“\ n”代替换行符。

#4


1  

Javascript has a specific AlertDialog that it opens when you you call alert('') and treats the entire body as text - far as I know there is no way of adding HTML to the displayed dialog.

当你调用alert('')并将整个主体视为文本时,Javascript有一个特定的AlertDialog,就像我知道没有办法在显示的对话框中添加HTML一样。

I'd recommend using a Javascript library that supports a customizable dialog box or modal box like this Modal Box to get your desired behavior (and it will look better)

我建议使用一个Javascript库,它支持一个可自定义的对话框或模态框,就像这个Modal Box一样,以获得你想要的行为(它看起来会更好)

#5


1  

You can't use markup in a javascript alert. However, you can achieve line breaks using "\n"

您无法在javascript警报中使用标记。但是,您可以使用“\ n”实现换行符

#6


1  

Alert is a fairly crude tool (and looks it too). Perhaps it's time to look at doing this in a more web friendly way...

警报是一个相当粗糙的工具(也看起来也是如此)。也许现在是时候以更友好的方式来看待这个......

Create a hidden message div on your page and instead of executing the alert, populate it with some message mark-up (including an anchor link if you wish) and reveal it to the user instead. You can add all kinds of nice visual tricks to this including fading in/out, centring, layering a semi-opaque background, etc, etc..

在您的页面上创建一个隐藏的消息div,而不是执行警报,用一些消息标记(如果您愿意,包括一个锚链接)填充它,并将其显示给用户。你可以添加各种漂亮的视觉技巧,包括淡入/淡出,居中,分层半透明背景等等。

edit: jQuery dialog (as mentioned by others) is a nice way to handle this, most libraries will have some widget or another to do similar.

编辑:jQuery对话框(正如其他人所提到的)是处理这个问题的好方法,大多数库都会有一些小部件或其他类似的东西。

#7


1  

Short answer: you can't. Javascript dialogs are basic.

简答:你不能。 Javascript对话框是基本的。

You can use VBScript's MsgBox method to create a custom dialog box but that'll only work on Internet Explorer with VBScript turned on. Not cross-platform; not recommended.

您可以使用VBScript的MsgBox方法创建自定义对话框,但这只能在启用了VBScript的Internet Explorer上运行。不是跨平台的;不建议。

The alternative is to fake it in HTML, which a large number of Javascript libraries provide built-in functionality for.

另一种方法是在HTML中伪造它,大量的Javascript库为其提供内置功能。

#8


1  

as Gumbo said, \n is working 100%. But don't forget to give spaces between text and the \n

正如Gumbo所说,\ n正在100%工作。但是不要忘记在文本和\ n之间留出空格

#9


0  

No, alert() only allows plain text. So \n is a line break.

不,alert()只允许纯文本。所以\ n是一个换行符。

#10


0  

Maybe you can try confirm() instead alert(). This solution is not a link, but a redirection from button.

也许你可以尝试confirm()而不是alert()。此解决方案不是链接,而是从按钮重定向。

If you wrap the confirm into other var and check for true/false, you can perform 2 actions.

如果将confirm包装到其他var并检查true / false,则可以执行2个操作。

var r=confirm("Do you wanna do"); if (r==true) { window.location.assign('register.html'); // this will be append to current url. For other, use http:// full url assignement. } else { window.location.assign(''); // cancel does nothing }

var r = confirm(“你想做”); if(r == true){window.location.assign('register.html'); //这将附加到当前网址。对于其他人,请使用http:// full url assignement。 } else {window.location.assign(''); //取消不做任何事情}

#1


51  

You can't use HTML, but you can add line breaks:

您不能使用HTML,但可以添加换行符:

alert('line1\nline2');

If a rich modal popup is really what you want though, you can use jQuery's dialog feature and put whatever you want in there.

如果你想要的是丰富的模态弹出窗口,你可以使用jQuery的对话框功能并在那里放置任何你想要的东西。

#2


14  

Use \\n (needs two slashes).

使用\\ n(需要两个斜杠)。

You'll notice that before doing this the alert will not post even a javascript error. \n will not work because the slash needs to be escaped.

您会注意到,在执行此操作之前,警报甚至不会发布javascript错误。 \ n将无法工作,因为需要转义斜杠。

#3


4  

You cannot allow links but you can have newlines.

您不能允许链接,但可以使用换行符。

Just use "\n" for a newline instead of <br/>.

只需使用“\ n”代替换行符。

#4


1  

Javascript has a specific AlertDialog that it opens when you you call alert('') and treats the entire body as text - far as I know there is no way of adding HTML to the displayed dialog.

当你调用alert('')并将整个主体视为文本时,Javascript有一个特定的AlertDialog,就像我知道没有办法在显示的对话框中添加HTML一样。

I'd recommend using a Javascript library that supports a customizable dialog box or modal box like this Modal Box to get your desired behavior (and it will look better)

我建议使用一个Javascript库,它支持一个可自定义的对话框或模态框,就像这个Modal Box一样,以获得你想要的行为(它看起来会更好)

#5


1  

You can't use markup in a javascript alert. However, you can achieve line breaks using "\n"

您无法在javascript警报中使用标记。但是,您可以使用“\ n”实现换行符

#6


1  

Alert is a fairly crude tool (and looks it too). Perhaps it's time to look at doing this in a more web friendly way...

警报是一个相当粗糙的工具(也看起来也是如此)。也许现在是时候以更友好的方式来看待这个......

Create a hidden message div on your page and instead of executing the alert, populate it with some message mark-up (including an anchor link if you wish) and reveal it to the user instead. You can add all kinds of nice visual tricks to this including fading in/out, centring, layering a semi-opaque background, etc, etc..

在您的页面上创建一个隐藏的消息div,而不是执行警报,用一些消息标记(如果您愿意,包括一个锚链接)填充它,并将其显示给用户。你可以添加各种漂亮的视觉技巧,包括淡入/淡出,居中,分层半透明背景等等。

edit: jQuery dialog (as mentioned by others) is a nice way to handle this, most libraries will have some widget or another to do similar.

编辑:jQuery对话框(正如其他人所提到的)是处理这个问题的好方法,大多数库都会有一些小部件或其他类似的东西。

#7


1  

Short answer: you can't. Javascript dialogs are basic.

简答:你不能。 Javascript对话框是基本的。

You can use VBScript's MsgBox method to create a custom dialog box but that'll only work on Internet Explorer with VBScript turned on. Not cross-platform; not recommended.

您可以使用VBScript的MsgBox方法创建自定义对话框,但这只能在启用了VBScript的Internet Explorer上运行。不是跨平台的;不建议。

The alternative is to fake it in HTML, which a large number of Javascript libraries provide built-in functionality for.

另一种方法是在HTML中伪造它,大量的Javascript库为其提供内置功能。

#8


1  

as Gumbo said, \n is working 100%. But don't forget to give spaces between text and the \n

正如Gumbo所说,\ n正在100%工作。但是不要忘记在文本和\ n之间留出空格

#9


0  

No, alert() only allows plain text. So \n is a line break.

不,alert()只允许纯文本。所以\ n是一个换行符。

#10


0  

Maybe you can try confirm() instead alert(). This solution is not a link, but a redirection from button.

也许你可以尝试confirm()而不是alert()。此解决方案不是链接,而是从按钮重定向。

If you wrap the confirm into other var and check for true/false, you can perform 2 actions.

如果将confirm包装到其他var并检查true / false,则可以执行2个操作。

var r=confirm("Do you wanna do"); if (r==true) { window.location.assign('register.html'); // this will be append to current url. For other, use http:// full url assignement. } else { window.location.assign(''); // cancel does nothing }

var r = confirm(“你想做”); if(r == true){window.location.assign('register.html'); //这将附加到当前网址。对于其他人,请使用http:// full url assignement。 } else {window.location.assign(''); //取消不做任何事情}