18-基础-ref *** 作 DOM

18-基础-ref  *** 作 DOM,第1张

概述<!DOCTYPE html><html><head> <meta charset='UTF-8'> <meta name='viewport' content='width=device-width,initial-scale=1.0'> <meta http-equiv='X-UA-Compatible' content='ie=edge'> <title @H_502_6@<!DOCTYPE HTML><HTML><head> <Meta charset='UTF-8'> <Meta name='vIEwport' content='wIDth=device-wIDth,initial-scale=1.0'> <Meta http-equiv='X-UA-Compatible' content='IE=edge'> <Title>document</Title></head><body> <div ID='app'> <!-- ref *** 作dom 1. 给要 *** 作的元素设置ref属性 值随便写 2. 在Js中选项mounted(){获取要 *** 作的dom元素}--> <input type="text" ref="txt"> <p ref='ppp'>pppppppp</p> <a href="#" ref='aaa'>aaaaaaaa</a> </div> <script src='./vue.Js'></script> <script> new Vue({ el: '#app',data: {},methods: {},mounted() { console.log("mounted被触发----"); this.$refs.txt.focus(); console.log(this.$refs.txt);//input标签 console.log(this.$refs.ppp); //p标签 console.log(this.$refs.aaa);//a标签 console.log('文本:' + this.$refs.aaa.innerText); //a标签的内容 } }); </script></body></HTML>

总结

以上是内存溢出为你收集整理的18-基础-ref *** 作 DOM全部内容,希望文章能够帮你解决18-基础-ref *** 作 DOM所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1075737.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存