我想要添加数据属性值与ajax get请求相同的样式
我的jquery代码:
jQuery(function($) {
get_stock();
function get_stock(){
$.ajax({
url: vdisain_vd.url,
type: 'GET',
success: function(res) {
console.log(JSON.parse(res)); // [ { "unique_id": "Warehouse A available", "available": "1" }, { "unique_id": "Warehouse B available", "available": "0" } ]
$.each(JSON.parse(res), function (i, item) {
console.log($(this).data('shape-title'))
if($(this).data('shape-title') == item.unique_id) {
$(this).attr('style', 'color:blue');
}
console.log('item: ' + item.unique_id)
});
setTimeout(function() { get_stock(); }, 1000)
}
});
}
});
示例如果仓库不可用,我想添加
color:blue;
如果可以的话
color:green;
data-shape-title == unique_id