gpt4 book ai didi

Javascript 函数仅适用于一个变量

转载 作者:行者123 更新时间:2023-11-28 20:21:19 24 4
gpt4 key购买 nike

我正在开发一个插件,但它现在只能工作一半了。问题是我从复选框中获取了一些变量,但该函数仅适用于复选框的最后一个选中的项目(在列表中),不适用于其他项目。

我的代码:

jQuery(document).ready(function(){

jQuery('#gap-filtedit input[type=button]').click(function(){
jQuery('.filter-checkbox:checked').each(function() {
getchecked = jQuery(this).data('rel');

val = '[gap ';
console.log(getchecked);

jQuery('.' + getchecked).each(function(){
val = val + getchecked + '=';
name = jQuery(this).find('label').data('id');
title = jQuery(this).find('input[type=text],select').val();

if (!title) title = '';
if (name != 'null') {

val = val + name + ':' + title + ', ';

}
});
});


window.send_to_editor( val );
});
});

日志将为我提供所选选项。但是,console.log 之后的函数仅适用于行中最后一个选定的项。

如何让该功能适用​​于每个选定的项目?

最佳答案

在 .each 语句中执行该函数:

jQuery(document).ready(function(){

jQuery('#gap-filtedit input[type=button]').click(function(){
jQuery('.filter-checkbox:checked').each(function() {
getchecked = jQuery(this).data('rel');

val = '[gap ';
console.log(getchecked);

jQuery('.' + getchecked).each(function(){
val = val + getchecked + '=';
name = jQuery(this).find('label').data('id');
title = jQuery(this).find('input[type=text],select').val();

if (!title) title = '';
if (name != 'null') {

val = val + name + ':' + title + ', ';
window.send_to_editor( val );

}
});
});



});
});

关于Javascript 函数仅适用于一个变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18275847/

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