我正在尝试执行下面的代码。它在 Chrome 和 Firefox 上运行良好,但在 IE 11 上却出现问题。
IE 中的错误消息是: SCRIPT1002:语法错误
代码是:
$("div#formFields").append(
$("<label/>").text(formField['Data'][i]['field_label']),
$("<input/>", {
type: text,
id: 'selectTest',
name: 'selectTest',
required: "true",
}),
);
<div id="formFields" >
</div>
请帮忙。
最佳答案
删除append中的最后一个逗号。请参阅下面的代码
<body id="banner">
<div id="formFields" ></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($){
$("#formFields").append(
$("<label/>").text("Texts"),
$("<input/>", {
type: "Texts",
id: 'selectTest',
name: 'selectTest',
required: "true",
})//Remove comma from here,
//Comma added at the end will cause syntax error in IE
);
});
</script>
</body>
关于javascript - Jquery .append() 在 Internet Explorer 11 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59680051/