Jquery返回值

编程入门 行业动态 更新时间:2024-10-27 23:31:30
本文介绍了Jquery返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用了代码:

jQuery.fn.MyFunction = function(){ return this.each(function() { attributes = "test"; return attributes; });}

但是当我打电话

var1 = $(this).MyFunction();alert(var1);

我有一个[对象],但不是测试。

I got an [object], but not the "test".

如何让jquery插件返回一些值?

How to allow jquery plugin return a some value?

推荐答案

jQuery插件通常用于返回一个jQuery对象,因此你可以链接方法调用:

jQuery plugins are generally designed to return a jQuery object so you can chain method calls:

jQuery("test").method1().method2() ...

如果要返回其他内容,请使用以下语法:

If you want to return something else, use the following syntax:

jQuery.fn.extend({ myFunction: function( args ) { attributes = "test"; return attributes; } });

,或使用 [] 。

更多推荐

Jquery返回值

本文发布于:2023-10-26 14:42:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1530444.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:返回值   Jquery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!