gpt4 book ai didi

javascript - 试图合并来自 jquery.each 函数的所有值

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

看看我的代码,我试图将 jquery.each 中的所有值组合成这样的字符串 ok,good,然后传递给 ajax 值。欣赏。或 array('ok','good') 也可接受

var global = {
"44":["onset","frequency"],
"45":["onset"]
};
var $val = global[44];

jQuery.each( $val, function( key ,value) {
var value = $('#'+value).val();
});
var $combine = ;//not sure how to combine all value like this (ok,good), or array(ok,good) acceptable also
var data= {
action: 'check_first',
AjaxFrontNonce : ajax_csky.AjaxFrontNonce,
combine : $combine
}
<input type="hidden" id="onset" value="ok">
<input type="hidden" id="frequency" value="good">

最佳答案

试试这个工作片段

var global = {
"44": ["onset", "frequency"],
"45": ["onset"]
};
var $val = global[44];
var arr = [];
$.each($val, function(key, val) {
var value = $('#' + val).val();
arr.push(value);
});

var $combine = arr; //not sure how to combine all value like this (ok,good), or array(ok,good) acceptable also
console.log($combine);
var data = {
action: 'check_first',
//AjaxFrontNonce : ajax_csky.AjaxFrontNonce, not defiend
combine: $combine
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="hidden" id="onset" value="ok">
<input type="hidden" id="frequency" value="good">

关于javascript - 试图合并来自 jquery.each 函数的所有值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38807704/

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