javascript - 获取当前元素(JavaScript 中的内联函数)?
问题描述
我试图通过在 div 本身中创建一个函数来获取元素本身当有人点击当前元素时我想要的元素应该通过淡入纯 JavaScript 来删除我在互联网上搜索过但没有得到答案有很多类似的Stack Overflow 上的问题,但没有一个给出综合答案(比如通过 Js in(内联函数)获取当前元素)。所以任何人都可以帮助我
<div style="width: 100px;height: 100px;background:red;" onclick="(function(ele){
console.log('helo')
console.log(ele.currentTarget)})();">
解决方案
这应该这样做:
我添加了一个id
可以div
通过getElementById
.
<div id='hello' style="width: 100px;height: 100px;background:red;" onclick="
(
function() {
document.getElementById('hello').style.opacity = 0;
document.getElementById('hello').style.transition = '0.5s';
}
)();">
推荐阅读
- angular - 在 Spring Boot 中将 Angular 中的 put 请求传递给后端时出现错误 400
- javascript - 从 ajax 响应中获取表列平均值
- ruby-on-rails - 模型的 rails 单元测试返回无效结果
- python - Python问题:如何解决while函数中的简单数字?
- playwright - Playwright 是否在命令行中提供自定义参数?
- java - React Native CLI 0.64 版设置任务':app:checkDebugDuplicateClasses'的执行失败。和任务:app:compileDebugJavaWithJavac FAILED
- python - 如果值重复,如何从字典中删除重复项
- excel - Excel VBA - 将一行中的单元格复制到非错误值
- java - android中的ViewModel和可变实时数据无法正常工作
- python - django-framework中这个错误是什么意思