gpt4 book ai didi

javascript - 将输入值设为数组

转载 作者:行者123 更新时间:2023-11-28 06:33:06 25 4
gpt4 key购买 nike

如何将输入值设置为数组

var obj = {};
var data = $('#provilege').val();
var obj = eval(data);

//var obj = {"test_1":"1","test_2":"1","test_3":"0","test_4":"0","test_5":"0","test_6":"1","test_7":"0"}

$.each( obj, function( key, value ) {
alert("key " + key + " has value " + obj[key]);
if(value == 0){
$('#'+ key).addClass('hidden');// hidden only the obj has value = 0
}
});

http://jsfiddle.net/8TT4p/1672/

感谢您的帮助;

最佳答案

使用JSON.parse()来解析JSON。

正确的值格式应该是这样的,我使用了 " 而不是 ',否则解析 JSON 时会出错:

{"test_1":"1","test_2":"1","test_3":"0","test_4":"0","test_5":"0","test_6":"1","test_7":"0"}

Updated demo

关于javascript - 将输入值设为数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34529640/

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