如何处理在JavaScript中单击事件? [英] How to handle click event in javascript?

查看:108
本文介绍了如何处理在JavaScript中单击事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天是我在新的工作岗位的第一天(在大型网站前端负责人。)我的一个任务是实现一个按钮,它的点击的时候触发一个事件。我没有任何线索,所以google搜索了一下后,我想出了这一点:

Today is my first day at a new job (a Front End Lead on a large website.) One of my tasks is to implement a button that fires an event when it's clicked. I had no clue, so after googling a bit, I came up with this:

<html>
<head>
<script type="text/javascript">
function popup(); 
{
    alert("Hello World") ==> alert("Hello World");
}
</script>
</head>
<body>

<input type="button" value="Click Me!" onclick="popup()"></input><br></br>

</html>    
</body>

问题是,当我点击我的按钮,没有任何反应。

The problem is, when I click my button, nothing happens.

修改根据米歇尔的意见更新

EDIT Updated based on MICHEL's comments

推荐答案

这应该工作

<html>
<head>
</head>

<body>

<script type="text/javascript">
function popup() 
{
    alert("Hello World");
}
</script>

<input type="button" value="Click Me!" onclick="popup()"><br/><br/>

</body>
</html>

这篇关于如何处理在JavaScript中单击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆