gpt4 book ai didi

javascript - insertBefore 语句中的参数无效

转载 作者:行者123 更新时间:2023-12-02 18:56:03 40 4
gpt4 key购买 nike

在此代码中:

function comrespond(){
function addresform(){
var resid = this.getAttribute('id'),
grandParent = this.parentNode.parentNode,
newrespondform = '<div class="commentresponse"><span></span><span><p class="author">Leave a reply:</p><form id="commentform" action="http://split.snippetspace.com/wp-comments-post.php" method="post" onsubmit="addcomment(); return false;"><input id="author" aria-required="true" name="author" type="text" placeholder="Your name"/><input id="email" aria-required="true" name="email" type="text" placeholder="Email address" /><textarea id="comment" aria-required="true" name="comment" rows="8"></textarea><input id="submit" name="submit" type="submit" value="Post Comment" /><input id="comment_post_ID" name="comment_post_ID" type="hidden" value="'+resid+'" /></form></span></div>';
grandParent.parentNode.insertBefore(newrespondform, grandParent.nextSibling);
}
var responsebtn = document.getElementsByClassName('comment-reply-link');
for(var i = 0; i < responsebtn.length; i++){
bindEvt(responsebtn[i], "click", addresform);
};

此行在 IE10 中返回为“无效参数”:

grandParent.parentNode.insertBefore(newrespondform, grandParent.nextSibling);

我似乎无法弄清楚这一点。它应该在某个 div 的祖 parent 之后插入一段代码。大家有什么想法吗? :)

最佳答案

newrespondform 是一个字符串。 insertBefore 接受一个 DOM 元素。您应该将其更改为:

newrespondform = document.createElement('div');
newrespondform.innerHTML = '<span></span><span><p class="author">Leave a reply:</p><form id="commentform" action="http://split.snippetspace.com/wp-comments-post.php" method="post" onsubmit="addcomment(); return false;"><input id="author" aria-required="true" name="author" type="text" placeholder="Your name"/><input id="email" aria-required="true" name="email" type="text" placeholder="Email address" /><textarea id="comment" aria-required="true" name="comment" rows="8"></textarea><input id="submit" name="submit" type="submit" value="Post Comment" /><input id="comment_post_ID" name="comment_post_ID" type="hidden" value="'+resid+'" /></form></span>';

这里是 insertBefore 的文档:https://developer.mozilla.org/en-US/docs/DOM/Node.insertBefore

关于javascript - insertBefore 语句中的参数无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15342341/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com