gpt4 book ai didi

IE9 中的 JavaScript 错误 :- SCRIPT5022: DOM Exception: INVALID_CHARACTER_ERR (5)

转载 作者:行者123 更新时间:2023-12-02 19:29:37 25 4
gpt4 key购买 nike

我在下面的代码行中遇到错误:

var input2 = document.createElement('<input name=\'password\' type=\'password\' id=\'password\' onblur=\'checkCopy(this)\' onkeyup=\'return handleEnterSubmission(this.form,event)\'  maxlength=\'16\' autocomplete=\'off\' onfocusin=\'checkValue(this.value, this.id);setMarginInIE();\' />');

在 IE8 中工作正常,但在 IE9 中出现问题。请告诉我这段代码有什么问题?

最佳答案

您的代码的主要错误是您显然从未阅读过 document.createElement() 的文档(例如 here )。

它说(强调我的):

var element = document.createElement(tagName);
  • element is the created element object.
  • tagName is a string that specifies the type of element to be created. The nodeName of the created element is initialized with the value of tagName.

您无法将完整的 HTML 字符串传递给 createElement。您可以传递标签名称:

var input2 = document.createElement('INPUT');

要创建完整的 HTML block ,请使用:

function createElementFromHTML(html) {
var temp = document.createElement('DIV');
temp.innerHTML = html;
return temp.childNodes[0];
}

关于IE9 中的 JavaScript 错误 :- SCRIPT5022: DOM Exception: INVALID_CHARACTER_ERR (5),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11674191/

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