【发布时间】:2016-08-15 08:28:11
【问题描述】:
* {
padding: 0;
margin: 0;
}
body {
font-family: sans-serif;
}
.grid {
width: 50%;
float: left;
padding: 30px 50px;
}
.container {
background: #e3e3e3;
}
textarea {
width: 100%;
height: 200px;
resize: none;
margin-top: 20px;
margin-bottom: 50px;
}
iframe {
border-style: solid;
border-color: aqua;
height: 1000px;
width: 100%;
display: block;
}
<!DOCTYPE HTML>
<hmtl>
<head>
<link rel = "stylesheet" type = "text/css" href = "style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script>
(function() {
$('grid').height($(window).height() );
var frame = $('iframe');
var contents = frame.contents();
var body = contents.find('body')
var styleTag = contents.find('head').append('<style></style>').children('style');
$('textarea').focus(function() {
var $this = $(this);
$this.keyup(function() {
if ($this.attr('id') == 'html') {
body.html($this.val() );
}
else
{
styleTag.text($this.val() );
}
});
});
});
</script>
</head>
<body>
<div class = "container grid">
<form>
<h2>HTML</h2>
<textarea id = "html"></textarea>
<h2>CSS</h2>
<textarea id = "css"></textarea>
</form>
</div>
<div class = "output grid">
<iframe></iframe>
</div>
</body>
</hmtl>
我正在尝试制作一个简单的在线 html 编辑器(如 codepen),但结果没有显示出来。我已经尝试解决这个问题一个多小时了!请帮忙!这个问题困扰着我,互联网也无济于事!我怀疑 jQuery 有问题,但看起来不像
【问题讨论】:
-
请编辑您的问题,使其比“结果未显示”更具体。
-
我希望用户在 html 和 css 文本区域中键入 html 代码,并将其“显示”在 iFrame 中。到目前为止,在 textarea 中键入 html 和 css 代码时,iFrame 似乎没有响应。
标签: javascript jquery html css iframe