Jquery返回值 [英] Jquery return value
本文介绍了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;
}
});
,或使用 [] $ c $通过索引访问它c>。
这篇关于Jquery返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文