我有饼干:
[{
"name": "Color",
"variant":
{
"name": "Blue"
}
},
{
"name": "Size",
"variant":
{
"name": "XL"
}
}]
我需要这样做(或类似的东西)
var city_id_cookie_load = Cookies.get('city_id_cookie')
我该怎么做?
我试试这个:
var $cities = $('#cities');
$cities.on('click', 'a', function() {}).find(city_id_cookie_load).trigger('click');
但我得到错误:
未捕获错误:语法错误,无法识别的表达式:$('#city-2')
答案 0 :(得分:0)
看起来您正在尝试在字符串中构建一个永远不会工作的jQuery对象。尝试在字符串中构建选择器:
var city_id_cookie_load = '#' + Cookies.get('city_id_cookie')
$cities.on('click', 'a', function() {
// your click handler logic...
}).find(city_id_cookie_load).trigger('click');