[英]error… Uncaught SyntaxError: Invalid or unexpected token… with JavaScript
I have this code.我有这个代码。 The error in Chrome is "Uncaught SyntaxError: Invalid or unexpected token".
Chrome 中的错误是“未捕获的语法错误:无效或意外的令牌”。 I am building an online "code checker/designer" similar to codepen just for fun(practice).
我正在构建一个类似于 codepen 的在线“代码检查器/设计器”,只是为了好玩(练习)。
I'm trying to get the user data from a textarea(the html, css and js) and display it in an iframe on the same page.我正在尝试从 textarea(html、css 和 js)获取用户数据并将其显示在同一页面的 iframe 中。 Any help would be greatly appreciated!
任何帮助将不胜感激!
$("textarea").on("change keyup paste", function() {
$("iframe").contents().find("html").html("<html><head><style type='text/css'>" +
$("#cssPanel").val() +
"</style></head><body>" +
$("#htmlPanel").val() +
"</body></html>");
});
The below works but only for html displaying in the iframe.以下工作但仅适用于在 iframe 中显示的 html。 As soon as I add the above code I get the error and nothing works/displays in the iframe.
一旦我添加了上面的代码,我就会收到错误消息,并且 iframe 中没有任何工作/显示。
$("textarea").on("change keyup paste", function() {
$("iframe").contents().find("html").html($("#htmlPanel").val());
});
$("#htmlPanel").val()
而不是这个试试$("#htmlPanel").innerHTML
It is working fine for me: Please check: http://jsfiddle.net/8j2u63zw/20/它对我来说工作正常:请检查: http : //jsfiddle.net/8j2u63zw/20/
CSS CODE :<textarea type"text" id="cssPanel">p {border-style: dotted dashed solid double;}</textarea>
HTML CODE : <textarea type"text" id="htmlPanel"><p><b>Test HTML</b></p></textarea>
<iframe>
<html>
</html>
</iframe>
$("textarea").on("change keyup paste", function(){
$("iframe").contents().find("html").html("<html><head><style type='text/css'>" + $("#cssPanel").val() + "</style></head><body>" + $("#htmlPanel").val() + "</body></html>");});
I believe you are running Live Server from visual studio code.我相信您正在从 Visual Studio 代码运行 Live Server。 somehow it just wouldnt translate the code for some reason ( http://127.0.0.1:5500/ - just wont work).
不知何故,它出于某种原因无法翻译代码( http://127.0.0.1:5500/ - 只是行不通)。 Try running the file directly from your explorer instead.
尝试直接从资源管理器中运行该文件。 (file:///testcode/index.html)
(file:///testcode/index.html)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.