繁体   English   中英

将 json object 注入 html 元件

[英]Inject json object to html element

I made an html page the has the following code and what I want to do is map a json element to the value of data-site-key to equal the object site-key instead of " 6LeoeSkTAAAAAA9rkZs5oS82l69OEYjKRZAiKdaF ".

config.json

{
  "sitekey": "6LeWwRkUAAAAAOBsau7KpuC9AV-6J8mhw4AjC3Xz",
  "bankPort": "8080"
}

HTML

 <html> <head> <title>Captcha Harvester</title> <script src="https://www.google.com/recaptcha/api.js" async defer></script> <body> <p id="output"></p> </body> </head> <body> <form action="/submit" method="POST"> <div class="g-recaptcha" id="captchaFrame" data-sitekey="6LeoeSkTAAAAAA9rkZs5oS82l69OEYjKRZAiKdaF" data-callback="sub"></div> </form> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> const remote = require('electron').remote const app = remote.app const ipcRenderer = require('electron').ipcRenderer function sub() { ipcRenderer.send('sendCaptcha', grecaptcha.getResponse()); grecaptcha.reset(); } </script> </body> </html>

像这样的东西?:

在此处输入图像描述

 const siteKey = { sitekey: "6LeWwRkUAAAAAOBsau7KpuC9AV-6J8mhw4AjC3Xz", bankPort: "8080" } const siteKeyString = JSON.stringify(siteKey) const div = document.getElementById("divTest") div.dataset.sitekey = siteKeyString console.log(div)
 <div id="divTest" data-sitekey ="">Inspect Me!</div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM