I have this code. The error in Chrome is "Uncaught SyntaxError: Invalid or unexpected token". I am building an online "code checker/designer" similar to codepen just for fun(practice).
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. 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. As soon as I add the above code I get the error and nothing works/displays in the 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/
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. somehow it just wouldnt translate the code for some reason ( http://127.0.0.1:5500/ - just wont work). Try running the file directly from your explorer instead. (file:///testcode/index.html)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.