javascript 如何提醒按钮内联

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18330917/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 11:31:00  来源:igfitidea点击:

How to alert inline of button

javascript

提问by Bong Yuth

I know already how to alert by use javascript or Jquery. But just onclick button I apply javascript external or internal. What I need is we alert inline of button Example:

我已经知道如何使用 javascript 或 Jquery 发出警报。但只是 onclick 按钮我应用 javascript 外部或内部。我需要的是我们提醒按钮的内联示例:

<button name="my_btn" id="my_btn" onClick="alert('Hello I am alert')">Alert</button>

If it is possible please tell me. I am waiting for all of you

如果可能,请告诉我。我在等你们

回答by Peter-Pan

I never really understand why someone wants to do it this way, but here is an inline alert on a button.

我从来没有真正理解为什么有人想这样做,但这里有一个按钮上的内联警报。

<button type="button" onclick="alert('Hello World')">Show Alert</button>

Here is the fiddle

这是小提琴

By the way, I believe this question has been answered

顺便说一句,我相信这个问题已经回答了

Did I answer your question?

我回答你的问题了吗?

回答by usman allam

<input type='button' onclick="javascript:alert('test');" value='Button'/>

回答by debel

You can use the following snippet to call the alertfunction from your HTML:

您可以使用以下代码段alert从 HTML调用该函数:

<input type="button" value="click me!" onclick="alert('your message here');" />

But it is generally accepted you should not inline JavaScript and not use alert. You can check this question for more: Flash Message - jQuery

但人们普遍认为不应内联 JavaScript 也不应使用警报。您可以查看此问题以了解更多信息:Flash Message - jQuery

回答by danielb

You can use:

您可以使用:

<input type='button' onclick="alert('a');" value='Button'/>