Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 按钮和警报?_Javascript_Html - Fatal编程技术网

Javascript 按钮和警报?

Javascript 按钮和警报?,javascript,html,Javascript,Html,我有一个按钮和一个文本 如果用户在文本框中输入“Hi”,然后单击按钮,他应该会收到一个javascript警报“HELLO!”,我该怎么做 谢谢只需在脚本中添加以下代码:- function hello() { if(document.getElementById("txtboxid").value == "HI") alert("HELLO"); } 在按钮的单击事件中调用上述函数。 <head> <script type="text/javascript

我有一个按钮和一个文本

如果用户在文本框中输入“Hi”,然后单击按钮,他应该会收到一个javascript警报“HELLO!”,我该怎么做


谢谢

只需在脚本中添加以下代码:-

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。你的问题是什么?我也有一个按钮。但是我把它弄坏了。