Javascript 按钮和警报?
我有一个按钮和一个文本 如果用户在文本框中输入“Hi”,然后单击按钮,他应该会收到一个javascript警报“HELLO!”,我该怎么做Javascript 按钮和警报?,javascript,html,Javascript,Html,我有一个按钮和一个文本 如果用户在文本框中输入“Hi”,然后单击按钮,他应该会收到一个javascript警报“HELLO!”,我该怎么做 谢谢只需在脚本中添加以下代码:- function hello() { if(document.getElementById("txtboxid").value == "HI") alert("HELLO"); } 在按钮的单击事件中调用上述函数。 <head> <script type="text/javascript
谢谢只需在脚本中添加以下代码:-
function hello()
{
if(document.getElementById("txtboxid").value == "HI")
alert("HELLO");
}
在按钮的单击事件中调用上述函数。
<head>
<script type="text/javascript">
function sayHello()
{
theTextbox = document.getElementById("myTextbox");
alert("Hello!");
alert(theTextbox.value);
if(theTextbox.value == "Hi")
{
alert("You did enter Hi in the textbox!");
}
}
</script>
</head>
<body>
<input type="text" id="myTextbox" />
<button onclick="sayHello()" text="Click me!" />
</body>
函数sayHello()
{
theTextbox=document.getElementById(“myTextbox”);
警惕(“你好!”);
警报(textbox.value);
if(theTextbox.value==“Hi”)
{
警报(“您在文本框中输入了Hi!”);
}
}
这听起来像是一个家庭作业问题,您尝试过哪些代码不适合您?请把它贴在这里。你可以使用JavaScript。你的问题是什么?我也有一个按钮。但是我把它弄坏了。