gpt4 book ai didi

javascript - 将 $this 传递给函数

转载 作者:可可西里 更新时间:2023-11-01 02:16:58 26 4
gpt4 key购买 nike

如何将 $this(self 关键字)传递给 Jquery 中的函数

$(document).ready(function() {

$('.nav a').click(function() {
var direction = $(this).attr("name");
submit_form($(this))
});

function submit_form(this)
{
// do some stuff with 'this'
}
});

最佳答案

将它包装在 $() 中使其成为一个 jQuery 对象。你会想做类似的事情

submit_form(this);

function submit_form(obj)
{
// Work with `obj` as "this"
// Or wrap it in $() to work with it as jQuery(this)
}

关于javascript - 将 $this 传递给函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3373723/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com