我知道如何使用.data(' id')获取数据属性,例如.. 但我无法弄清楚如何获得" attachment_id"值包含在" data-kgvid_video_vars" ?
这就是我想要进入的地方所以我可以在其他地方使用它。
alert(jQuery(this).find('.kgvid_videodiv').data('id'));
data-kgvid_video_vars='{"id":"kgvid_16","attachment_id":116,"player_type":"Video.js","width":"640","height":"360","fullwidth":"true","countable":true,"count_views":"start_complete","start":"","autoplay":"false","pauseothervideos":"true","set_volume":"1","mute":"false","meta":true,"endofvideooverlay":"","resize":"true","auto_res":"automatic","pixel_ratio":"true","right_click":"on","playback_rate":"false","nativecontrolsfortouch":"false","locale":"en","enable_resolutions_plugin":false}'
答案 0 :(得分:-1)
从html组件获取属性的值:
kgvid_video_vars= jQuery(this).find('.kgvid_videodiv').data('kgvid_video_vars');
在javascript中获取json变量的值:
kgvid_video_vars= '{"id":"kgvid_16","attachment_id":116}';
jsonData = JSON.parse(kgvid_video_vars);
alert(jsonData.attachment_id);
请参阅JSON.parse()
完成回答你的问题
kgvid_video_vars= jQuery(this).find('.kgvid_videodiv').data('kgvid_video_vars');
jsonData = JSON.parse(kgvid_video_vars);
alert(jsonData.attachment_id);
答案 1 :(得分:-1)
var data-kgvid_video_vars = JSON.parse(jQuery(this).find('.kgvid_videodiv').data('data-kgvid_video_vars'));
alert(data-kgvid_video_vars["attachment_id"])