Rai*_*nne 16 html javascript events onclick
我正在学习JavaScript,最近我一直在试验鼠标事件,试图了解它们是如何工作的.
<html>
<head>
<title>Mouse Events Example</title>
<script type="text/javascript">
function handleEvent(oEvent) {
var oTextbox = document.getElementById("txt1");
oTextbox.value += "\n" + oEvent.type;
if(oEvent.type=="click")
{
var iScreenX = oEvent.screenX;
var iScreenY = oEvent.screenY;
var b = "Clicked at "+iScreenX+" , "+iScreenY;
alert(b);
}
}
function handleEvent1(oEvent) {
// alert("Left Window");
}
</script>
</head>
<body>
<p>Use your mouse to click and double click the red square</p>
<div style="width: 100px; height: 100px; background-color: red"
onmouseover="handleEvent(event)"
onmouseout="handleEvent1(event)"
onmousedown="handleEvent(event)"
onmouseup="handleEvent(event)"
onclick="handleEvent(event)"
ondblclick="handleEvent(event)" id="div1"></div>
<p><textarea id="txt1" rows="15" cols="50"></textarea></p>
</body>
Run Code Online (Sandbox Code Playgroud)
这是我一直试图理解的代码.任何人都可以帮我创建一个HTML表格,当点击表格的单元格时,用户被告知他正在点击的单元格?一直坚持下去,谢谢你的帮助.
Cil*_*lan 27
var table = document.getElementById("tableID");
if (table != null) {
for (var i = 0; i < table.rows.length; i++) {
for (var j = 0; j < table.rows[i].cells.length; j++)
table.rows[i].cells[j].onclick = function () {
tableText(this);
};
}
}
function tableText(tableCell) {
alert(tableCell.innerHTML);
}
Run Code Online (Sandbox Code Playgroud)
是你可以做的一个例子. DEMO
只需插入onclick到每个<td>表中,如果单元格的名称是示例,您可以执行与此类似的操作:
<td onclick="alert('You are clicking on the cell EXAMPLE')">
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
76772 次 |
| 最近记录: |