我设法在 http://hexagonest.tk/code/ 创建了一个 HTML/CSS 编辑器,但我无法管理它来使用 Javascript。我不确定为什么,所有代码都是有效的。例如,继续 this jfiddle ,然后输入以下代码:
<script>
function dothis(){
document.getElementById("thewow").innerHTML = "poop!";
}
</script>
<button type="button" onclick="dothis()">Hi</button>
<p id="thewow">Hi</p>
理论上,它应该有效,是吗?即使当我右键单击>检查元素时,它也显示有一个有效标签。这有什么问题吗?
如果你没看出来,我的问题是 Javascript 现在可以与我的实时 HTML 编辑器一起工作。
最佳答案
试试这个
<button type="button" onclick="document.getElementById('thewow').innerHTML = 'poop!'">try me</button>
嗨
---附加---
使用这个脚本来玩你的代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR...nsitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
textarea, iframe {width:200px;height:200px;}
td {vertical-align:top;text-align:center;}
</style>
<script type="text/javascript">
function tryit()
{
var html = document.getElementById("code").value;
ifrm = document.getElementById("output");
var doc = ifrm.contentDocument || ifrm.contentWindow.document;
doc.open();
doc.write(html);
doc.close();
}
</script>
</head>
<body>
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td>
<textarea id="code"><html><body>Hello World!</body></html></textarea>
<br />
<button onclick="tryit();">Do it!</button>
</td>
<td>
<iframe id="output"></iframe>
</td>
</tr>
</table>
</body>
</html>
来源http://w3schools.invisionzone.com/index.php?showtopic=23599
关于javascript - 从 textarea 编辑 Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21541656/