JQuery Prepend 不会粘贴可用的 html 代码
JQuery Prepend does not paste usable html code
我正在尝试为我正在创建的网站使用 recaptcha v3。
我遇到的问题是,每次我像这样使用 jquery 前置函数时:
grecaptcha.ready(function () {
// do request for recaptcha token
// response is promise with passed token
grecaptcha.execute('6Lf8MasZAAAAAPM2b9qSmFSwy4nOXMNbu9MxrZbx', {action: 'create_comment'}).then(function (token) {
// add token to form
document.getElementById('login-form').prepend('<input type="hidden" name="g-recaptcha-response" value="' + token + '">');
});
});
它在网站上这样做:
<form id="login-form" class="login-form"><input type="hidden" name="g-recaptcha-response" value="03AGdBq24R7iIJoeIQecS7iwknDmE1wZI3I9cNs789wbkIdYCHaXeLXrM2N15zmKFqi026YKrrxpA-0wGlXlXwP0rVOkYbOQYWodkjP5YFDs6aWE35tdqg_4JP7WskTh75SDWa5DCSWkJBPxynLR2x1nWlUgie4MCo8SIS6C3XmSewf9uHfJvVb6z6Un0aW6Jnm1Ee4qMNsSlZKRd94sLecXWXA-pdEqA31VN13FFPZNVs5d_LR59zf5217F7NlAoO5WpNJ5ey-qT51ChhqLOrRpihZ9rW3xbi7G-shOcgwcX8Tapz02BW6V4mQuA8tAkHt00buI9Ylb1pSE4wK5RCYgkEppds3FDzRhcPgWDH2q8LyuGueNVi_J832S2jXy-qi6E-4ZpZThpg-Fo3G31xwB2mwiekT2wH_tIICngzv3w3oXsHl8LgsdHcv_yFsgKUWTuZjXqBlMnQU-PbyWffAtzGG7heJH-42A">
<div class="field">
<div class="control">
<input class="input is-medium" name="email" type="email" placeholder="Email">
</div>
</div>
<div class="field">
<div class="control">
<input class="input is-medium" name="password" type="password" placeholder="Password">
</div>
</div>
<a href="#"><button id="login-button" type="button" class="button is-block is-primary is-fullwidth is-medium">Submit</button></a>
<br>
<small><em>Lorem ipsum dolor sit amet consectetur.</em></small>
</form>
你们知道如何解决这个问题吗?因为现在它看起来像这样:
对于纯 js 前置工作机智节点而不是字符串你可以像下面那样用 purejs
var form=document.getElementById('login-form');
form.innerHTML='<input type="hidden" name="g-recaptcha-response" value="' + token + '"/>'+form.innerHTML;
或者您可以导入 jquery 并像下面那样使用它
$("#login-form").prepend('<input type="hidden" name="g-recaptcha-response" value="' + token + '"/>')
我正在尝试为我正在创建的网站使用 recaptcha v3。 我遇到的问题是,每次我像这样使用 jquery 前置函数时:
grecaptcha.ready(function () {
// do request for recaptcha token
// response is promise with passed token
grecaptcha.execute('6Lf8MasZAAAAAPM2b9qSmFSwy4nOXMNbu9MxrZbx', {action: 'create_comment'}).then(function (token) {
// add token to form
document.getElementById('login-form').prepend('<input type="hidden" name="g-recaptcha-response" value="' + token + '">');
});
});
它在网站上这样做:
<form id="login-form" class="login-form"><input type="hidden" name="g-recaptcha-response" value="03AGdBq24R7iIJoeIQecS7iwknDmE1wZI3I9cNs789wbkIdYCHaXeLXrM2N15zmKFqi026YKrrxpA-0wGlXlXwP0rVOkYbOQYWodkjP5YFDs6aWE35tdqg_4JP7WskTh75SDWa5DCSWkJBPxynLR2x1nWlUgie4MCo8SIS6C3XmSewf9uHfJvVb6z6Un0aW6Jnm1Ee4qMNsSlZKRd94sLecXWXA-pdEqA31VN13FFPZNVs5d_LR59zf5217F7NlAoO5WpNJ5ey-qT51ChhqLOrRpihZ9rW3xbi7G-shOcgwcX8Tapz02BW6V4mQuA8tAkHt00buI9Ylb1pSE4wK5RCYgkEppds3FDzRhcPgWDH2q8LyuGueNVi_J832S2jXy-qi6E-4ZpZThpg-Fo3G31xwB2mwiekT2wH_tIICngzv3w3oXsHl8LgsdHcv_yFsgKUWTuZjXqBlMnQU-PbyWffAtzGG7heJH-42A">
<div class="field">
<div class="control">
<input class="input is-medium" name="email" type="email" placeholder="Email">
</div>
</div>
<div class="field">
<div class="control">
<input class="input is-medium" name="password" type="password" placeholder="Password">
</div>
</div>
<a href="#"><button id="login-button" type="button" class="button is-block is-primary is-fullwidth is-medium">Submit</button></a>
<br>
<small><em>Lorem ipsum dolor sit amet consectetur.</em></small>
</form>
你们知道如何解决这个问题吗?因为现在它看起来像这样:
对于纯 js 前置工作机智节点而不是字符串你可以像下面那样用 purejs
var form=document.getElementById('login-form');
form.innerHTML='<input type="hidden" name="g-recaptcha-response" value="' + token + '"/>'+form.innerHTML;
或者您可以导入 jquery 并像下面那样使用它
$("#login-form").prepend('<input type="hidden" name="g-recaptcha-response" value="' + token + '"/>')