Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在jquery'中添加自定义对象;s对象_Jquery_Custom Object - Fatal编程技术网

在jquery'中添加自定义对象;s对象

在jquery'中添加自定义对象;s对象,jquery,custom-object,Jquery,Custom Object,我想在jquery对象中添加属性。我试图在jquery的上下文中添加属性。我控制台jquery对象console.log($(this)),它看起来像一个对象。但是,当我试图修改代码时,代码不起作用 您可以在HTML中的数据属性中添加数据,因此可以选择存储: $(this).data('myul', {'date':'28 april'}); 更新后的JSFIDLE如下:您可以在HTML中的数据属性中添加数据,因此可以选择存储: $(this).data('myul', {'date':'28

我想在jquery对象中添加属性。我试图在jquery的上下文中添加属性。我控制台jquery对象console.log($(this)),它看起来像一个对象。但是,当我试图修改代码时,代码不起作用


您可以在HTML中的数据属性中添加数据,因此可以选择存储:

$(this).data('myul', {'date':'28 april'});

更新后的JSFIDLE如下:

您可以在HTML中的数据属性中添加数据,因此可以选择存储:

$(this).data('myul', {'date':'28 april'});

更新后的JSFIDLE如下:

您可以在HTML中的数据属性中添加数据,因此可以选择存储:

$(this).data('myul', {'date':'28 april'});

更新后的JSFIDLE如下:

您可以在HTML中的数据属性中添加数据,因此可以选择存储:

$(this).data('myul', {'date':'28 april'});

更新后的JSFIDLE如下:

您甚至不需要jquery:

 this['myul'] = '"date":"28 april"';
 console.log($(this))

您甚至不需要jquery:

 this['myul'] = '"date":"28 april"';
 console.log($(this))

您甚至不需要jquery:

 this['myul'] = '"date":"28 april"';
 console.log($(this))

您甚至不需要jquery:

 this['myul'] = '"date":"28 april"';
 console.log($(this))

问题在于每次创建新的jQuery包装时调用$(this),因此每次添加到前一个对象的内容在新对象中都不可用

您可以使用
$(this)==$(this)
测试它,它将返回
false

正确的方法是使用


演示:

问题在于每次创建新的jQuery包装器时调用$(this),因此每次添加到前一个对象的内容在新对象中都不可用

您可以使用
$(this)==$(this)
测试它,它将返回
false

正确的方法是使用


演示:

问题在于每次创建新的jQuery包装器时调用$(this),因此每次添加到前一个对象的内容在新对象中都不可用

您可以使用
$(this)==$(this)
测试它,它将返回
false

正确的方法是使用


演示:

问题在于每次创建新的jQuery包装器时调用$(this),因此每次添加到前一个对象的内容在新对象中都不可用

您可以使用
$(this)==$(this)
测试它,它将返回
false

正确的方法是使用


演示:

为什么每次调用
$(此)
将创建新的jQuery包装时都要这样做?为什么每次调用
$(此)
将创建新的jQuery包装时都要这样做每次创建新的jQuery包装时为什么要在每次创建新的jQuery包装时调用
$(this)
时这样做