Ama*_*nth 1 html javascript jquery angularjs
想知道是否有人可以帮助我了解如何在鼠标悬停事件中针对元素的 ID 值进行测试。我假设我必须使用“这个”。
我为 ID 获得的值是“未定义”
function mouseOver() {
var e = $(this).attr("ID"); //need help with this bit
if (e == ("row2012")) {
alert(e)
} else {
alert(e);
}
}Run Code Online (Sandbox Code Playgroud)
<table>
<tr data-ng-repeat="x in Interruptions">
<td id=row{{x.year}} onmouseover="mouseOver()" onmouseout="mouseOut()">
{{x.year}}
</td>
<td>{{x.totalEvents}}</td>
<td>{{x.customers}}</td>
<td>{{x.avgDuration}}</td>
</table>Run Code Online (Sandbox Code Playgroud)
您可以通过传递this内部onmouseover&onmouseout函数直接传递当前的 dom 元素,例如:
<td id=row{{x.year}} onmouseover="mouseOver(this)" onmouseout="mouseOut(this)">{{x.year}}</td>
Run Code Online (Sandbox Code Playgroud)
然后访问idjs 代码中的元素,如:
function mouseOver(elem) {
var e = elem.id;
if (e == "row2012") {
alert(e)
} else {
alert(e);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
378 次 |
| 最近记录: |