javascript - 如何制作 $(this) 的 this?

标签 javascript jquery

<分区>

这是我的代码:

$(.clsname).on("click", function(){
    do_something($(this));
});

function do_something(sth){
    /*
     * in here sth equals $(this)
     * and I want to get "this" of "$(this)"
     *
     * EX: this.value = "some value";
     * I know I can do that like sth.val("some value");
     * but I need to do that by following the first version (using "this")
     */
}

如您所见,我的问题在上面的代码中有注释。我该怎么做?

最佳答案

就用

sth[0]

这将转换为 DOM 对象

您还可以对 jQuery 对象使用 get 方法。

sth.get(0)//从 jQuery 对象中提取原生 DOM 元素。

也会给你同样的结果。

关于javascript - 如何制作 $(this) 的 this?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41770266/

相关文章:

javascript - 如何从字典中填充大型数据列表(~2000 项)

javascript - 更新 : D3 won't draw chart data on load

javascript - 同步发出多个ajax请求

javascript - jqWidgets 选项卡内的 jQuery Chosen 下拉列表未正确呈现

javascript - 滚动到最近的 href 选项卡 jquery

javascript - 变量未定义问题

javascript - 如何通过引用 JavaScript 中的事件处理程序来传递变量?

javascript - 元素不可见错误(无法单击元素)

javascript - 了解操作是否成功或被 promise 拒绝

JavaScript 拼接超过 1 个值?