您的位置:首页 > 编程语言

”运行代码”功能是如何实现的?

2014-03-04 17:26 316 查看
在很多网站中,我们都可以看到有一个东西,只要我们把代码粘贴上去,点击运行按钮,就直接可以看到效果。

而这个“运行代码”部分是如何实现的呢?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>实现"运行代码"按钮</title>
</head>
<body>
<script type="text/javascript">
function Preview(obj) {
var Test = open('');
Test.document.write(obj.value);
}
</script>
<textarea id="content" style="width: 570px; height: 244px" rows="15" cols="47">
</textarea>
<br /><button onclick="javascript:Preview(content)">运行代码</button>
</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐