this和$(this)区别

this是html元素,$(this)是变量名。$(this)=jquery(this)顾返回的是一个jQ对象。
this是dom对象不可以直接使用jQ中的方法,通过$(this)转换为jQ对象就可以使用jQ中的方法了。
如下:this使用siblings()时会报错,而转为$(this)就可以使用该方法了。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>this和$(this)</title>
</head>
<body>
<div>
<input type="text" value="1">
<button id="btn">按钮</button>
</div>
<script type="text/javascript" src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
   $("#btn").click(function(){
    alert(this);//[object HTMLButtonElement]
    alert($(this));//[object Object]
console.log(this.siblings());//报错:this.siblings is not a function
    console.log($(this).siblings());//[input, prevObject: init(1), context: button#btn]

   })
</script>
</body>
</html>

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
this.$是Vue框架中的一个全局对象,它提供了许多有用的方法和属性。常见的使用方式有this.$router和this.$http。 this.$router是Vue Router的实例,用于进行页面之间的跳转操作。通过调用this.$router.push(参数)方法,可以实现页面的跳转。参数可以是一个字符串路径,也可以是一个包含路径和查询参数的对象。例如,this.$router.push("/")会将当前页面跳转到根路径。 this.$http是Vue Resource或者Axios库的实例,用于发送HTTP请求。通过调用this.$http.post(路径, 数据)方法,可以向指定的路径发送POST请求,并传递相应的数据。 总结起来,this.$router提供了页面跳转的功能,而this.$http则提供了发送HTTP请求的功能。这两个对象在Vue框架中都非常常用,对于Vue开发者来说是必不可少的工具。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Vue this.$router.push(参数)实现页面跳转操作](https://download.csdn.net/download/weixin_38738511/12923401)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [解决vue.js this.$router.push无效的问题](https://download.csdn.net/download/weixin_38702339/13588275)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [vue.js this.$router.push获取不到params参数问题](https://download.csdn.net/download/weixin_38656142/12927619)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值