[英]How to get value of an objet in an attribute?
Hope you're well.希望你一切都好。 I need your help today.
我今天需要你的帮助。
I've got on my page a which contains attributes.我在我的页面上有一个包含属性的。 One of these, named data-params, contains an object.
其中一个名为 data-params,包含一个对象。 In this object we've got a lot of data and I want to get only one value.
在这个对象中,我们有很多数据,我只想得到一个值。 I tried to use
Object.keys
OR element.attributes
but it doesn't work.我尝试使用
Object.keys
OR element.attributes
但它不起作用。 I really don't know how and where to search.我真的不知道如何以及在哪里搜索。 It seems this object looks like JSON.
看起来这个对象看起来像 JSON。
By the way thanks a lot by advance for your help and happy coding :)顺便说一句,非常感谢您的帮助和愉快的编码:)
PS : Here the code of the : PS:这里的代码:
<div id="wpws-live" data-params="{"cache_url":"https:\\/\\/www.ecommerce-nation.fr\\/wp-content\\/plugins\\/wpwebinarsystem\\/cache\\/webinar_808227d5-f2e7-480d-b438-19f2d0e6feb8_v2.json","secure_room_name":"96269b8f-3ce6-47f2-8c64-92e62291799a","secure_room_key":"e2324107-c6b6-42a8-8a79-a5bdfc26ac32","reduce_server_load":false,"webinar_time_in_seconds":3465657,"webinar_start_time":1591194600,"duration":3600,"timezone_offset":120,"attendee":{"id":477,"name":"blablablo","email":"blablablo@yopmail.com","is_team_member":true},"translations":{"webinarSummaryStartingTimer":"Commence \à","webinarSummaryStartWebinar":"Lancer le webinar","webinarSummaryStopBroadcasting":"Stopper le webinar","webinarSummaryLogout":"Quitter le webinar","webinarTimerDays":"jours","webinarTimerHours":"heures","webinarTimerMinutes":"minutes","webinarTimerSeconds":"secondes","webinarTabsPeople":"Explorateurs","webinarChatEmpty":"Personne n'a encore parl\é... Lancez la conversation !","webinarChatPlaceholder":"Appuyez sur Entrer pour envoyer votre message","webinarChatMenuDelete"</div></div></div></div></div></div></div></div></div></main></div>
The data-params
string seems to be incomplete. data-params
字符串似乎不完整。 I did some "repair work" on it and managed to process it as shown below:我对它做了一些“修复工作”并设法处理它,如下所示:
let d=document.querySelector("#wpws-live"),jsn=d.dataset.params, o=JSON.parse(jsn); d.textContent=o.attendee.email; // display a single property in the div console.log(o); // list the whole object with all its properties
.as-console-wrapper { max-height: 80% !important;}
<div id="wpws-live" data-params="{"cache_url":"https:\\/\\/www.ecommerce-nation.fr\\/wp-content\\/plugins\\/wpwebinarsystem\\/cache\\/webinar_808227d5-f2e7-480d-b438-19f2d0e6feb8_v2.json","secure_room_name":"96269b8f-3ce6-47f2-8c64-92e62291799a","secure_room_key":"e2324107-c6b6-42a8-8a79-a5bdfc26ac32","reduce_server_load":false,"webinar_time_in_seconds":3465657,"webinar_start_time":1591194600,"duration":3600,"timezone_offset":120,"attendee":{"id":477,"name":"blablablo","email":"blablablo@yopmail.com","is_team_member":true},"translations":{"webinarSummaryStartingTimer":"Commence \à","webinarSummaryStartWebinar":"Lancer le webinar","webinarSummaryStopBroadcasting":"Stopper le webinar","webinarSummaryLogout":"Quitter le webinar","webinarTimerDays":"jours","webinarTimerHours":"heures","webinarTimerMinutes":"minutes","webinarTimerSeconds":"secondes","webinarTabsPeople":"Explorateurs","webinarChatEmpty":"Personne n'a encore parl\é... Lancez la conversation !","webinarChatPlaceholder":"Appuyez sur Entrer pour envoyer votre message"}}">the div</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.