this指向问题,标签上绑定onclick事件this指向问题
source link: https://blog.p2hp.com/archives/9067
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
this指向问题,标签上绑定onclick事件this指向问题 | Lenix Blog
<input type="button" value="修改" οnclick="changeContent()">
写在元素上onclick里面的函数changeContent,相当于函数直接调用,函数里面使用的this指向全局对象window,
而不是指向该元素
那么要获取onclick所在节点的object,我们则需要在调用function时就把this传递过去:
<input type="button" value="修改" οnclick="changeContent(this)">
这里的this指这个input标签,$(this)将其变为jq对象;
function changeContent(e){
var _this = $(this)
- admin发表在《博客声明》
- ke发表在《使用FFMPEG生成HLS》
- XRumerTest发表在《Ubuntu 命令技巧》
- order online canada发表在《PHP 知识补全 —— 生成器 (generator)和协程的实现》
- manicure发表在《PHP 7 性能改进 (1/5): Packed arrays》
- James发表在《php实现协程,真正的异步》
- https://www.viagrasansordonnancefr.com/achat-sildenafil-citrate-bodybuilding/发表在《文件服务器集群 采用Rsync+sersync同步主从文件FTP》
- ssss发表在《PHP 知识补全 —— 生成器 (generator)和协程的实现》
- manicure发表在《PHP 7 性能改进 (1/5): Packed arrays》
- 聂永发表在《Tsung笔记之主从资源协调篇》
- Apache (18)
- Go (3)
- Linux (71)
- Mac OS (16)
- Mysql (191)
- Nginx (67)
- Nosql (44)
- PHP (625)
- Vim (9)
- web前端 (181)
- Wordpress (7)
- 个人日志 (33)
- 云计算 (2)
- 人工智能 (7)
- 创业 (10)
- 工具 (67)
- 建站 (74)
- 开源 (7)
- 收费 (10)
- 架构 (114)
- 概念 (135)
- 物联网 (18)
- 移动互联网 (10)
- 编程 (190)
- 趋势 (6)
- 音视频 (4)
归档
分类总数:26个 标签总数:320个
友情链接:9个 网站运行:3812天
最后更新:2022年7月13日
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK