-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
166 lines (146 loc) · 4.17 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<title>WebflyEditor</title>
<link rel="shortcut icon" href="WebflyEditor.png">
<link rel="stylesheet" href="codemirror.css">
<style>
* {
margin: 0;
padding: 0
}
.wrap {
width: 100%;
height: 100%;
}
.header {
width: 100%;
height: 60px;
background: #96b97d;
display: flex;
align-items: center;
justify-content: center;
color: white;
}
.content {
margin-top: 40px;
display: flex;
justify-content: space-around;
padding: 0 20px;
}
.input {
width: 650px;
height: 500px;
border: 1px solid #ddd;
box-shadow: 0 1px 1px rgba(0, 0, 0, .05);
}
.input_title {
width: 650px;
height: 60px;
background-color: #f5f5f5;
border-bottom: 1px solid #ddd;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 20px;
box-sizing: border-box;
}
input[type='button'] {
border: 1px solid #ddd;
outline: none;
width: 85px;
height: 40px;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
color: #333333;
border-radius: 5px;
background: #fff;
}
.input_area {
width: 650px;
height: calc(500px - 60px);
box-sizing: border-box;
}
textarea {
width: 650px;
height: calc(500px - 60px);
border: none;
outline: none;
resize: none;
}
iframe {
width: 650px;
height: calc(500px - 60px);
border: none;
outline: none;
}
.CodeMirror {
position: relative;
overflow: hidden;
background: white;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div class="wrap">
<div class="header">
<h1>Qianwei</h1>
</div>
<div class="content">
<div class="input">
<div class="input_title">
<input type="button" value="源代码">
<input type="button" value="运行" id="run">
</div>
<div class="input_area">
<textarea id="code" name="code"></textarea>
</div>
</div>
<div class="input">
<div class="input_title">
<input type="button" value="运行结果">
</div>
<div class="input_area" id="result">
</div>
</div>
</div>
</div>
<script src="codemirror.js"></script>
<script src="jQuery.min.js"></script>
<script src="javascript.js"></script>
<script src="xml.js"></script>
<script src="css.js"></script>
<script src="htmlmixed.js"></script>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true, // 显示行数
indentUnit: 4, // 缩进单位为4
styleActiveLine: true, // 当前行背景高亮
matchBrackets: true, // 括号匹配
mode: 'htmlmixed', // HMTL混合模式
lineWrapping: true // 自动换行
});
var Run = document.querySelector("#run");
var Result = document.querySelector("#result");
Run.onclick = function () {
Result.innerHTML = "";
var htmlCode = editor.getValue();
// 1. 创建<iframe>元素
var iframe = document.createElement('iframe');
// 2. 将CSS,HTML字符串转换为Blob对象
var blob = new Blob([htmlCode], {
'type': 'text/html'
});
// 3. 使用URL.createObjectURL()方法将...
iframe.src = URL.createObjectURL(blob);
Result.appendChild(iframe)
}
</script>
</body>
</html>