1+ <!DOCTYPE html>
2+ < html lang ="zh-CN ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6+ < title > CodeForge HTML 代码示例</ title >
7+ < style >
8+ body {
9+ font-family : 'Consolas' , 'Monaco' , 'Courier New' , monospace;
10+ background : linear-gradient (135deg , # 667eea 0% , # 764ba2 100% );
11+ color : # 333 ;
12+ margin : 0 ;
13+ padding : 20px ;
14+ line-height : 1.6 ;
15+ }
16+
17+ .container {
18+ max-width : 900px ;
19+ margin : 0 auto;
20+ background : rgba (255 , 255 , 255 , 0.95 );
21+ padding : 30px ;
22+ border-radius : 15px ;
23+ box-shadow : 0 10px 30px rgba (0 , 0 , 0 , 0.2 );
24+ }
25+
26+ .header {
27+ text-align : center;
28+ border : 2px solid # 4CAF50 ;
29+ padding : 20px ;
30+ margin-bottom : 30px ;
31+ background : # f8f9fa ;
32+ border-radius : 10px ;
33+ }
34+
35+ .section {
36+ margin : 20px 0 ;
37+ padding : 15px ;
38+ background : # f0f8ff ;
39+ border-left : 4px solid # 2196F3 ;
40+ border-radius : 5px ;
41+ }
42+
43+ .output {
44+ background : # 1a1a1a ;
45+ color : # 00ff00 ;
46+ padding : 15px ;
47+ border-radius : 8px ;
48+ font-family : 'Courier New' , monospace;
49+ margin : 10px 0 ;
50+ overflow-x : auto;
51+ }
52+
53+ .button-container {
54+ text-align : center;
55+ margin : 20px 0 ;
56+ }
57+
58+ .btn {
59+ background : # 4CAF50 ;
60+ color : white;
61+ padding : 10px 20px ;
62+ border : none;
63+ border-radius : 5px ;
64+ cursor : pointer;
65+ font-size : 16px ;
66+ margin : 5px ;
67+ transition : background 0.3s ;
68+ }
69+
70+ .btn : hover {
71+ background : # 45a049 ;
72+ }
73+
74+ .fruit-list {
75+ list-style : none;
76+ padding : 0 ;
77+ }
78+
79+ .fruit-list li {
80+ background : # e8f5e8 ;
81+ margin : 5px 0 ;
82+ padding : 8px ;
83+ border-radius : 5px ;
84+ border-left : 3px solid # 4CAF50 ;
85+ }
86+
87+ .score-display {
88+ font-size : 18px ;
89+ font-weight : bold;
90+ padding : 10px ;
91+ border-radius : 5px ;
92+ text-align : center;
93+ }
94+
95+ .excellent {
96+ background : # d4edda ;
97+ color : # 155724 ;
98+ }
99+
100+ .good {
101+ background : # cce5ff ;
102+ color : # 004085 ;
103+ }
104+
105+ .pass {
106+ background : # fff3cd ;
107+ color : # 856404 ;
108+ }
109+
110+ .improvement {
111+ background : # f8d7da ;
112+ color : # 721c24 ;
113+ }
114+ </ style >
115+ </ head >
116+ < body >
117+ < div class ="container ">
118+ <!-- 头部信息 -->
119+ < div class ="header ">
120+ < h1 > 🎉 欢迎使用 CodeForge!</ h1 >
121+ < h2 > Welcome to CodeForge!</ h2 >
122+ < hr >
123+ < h3 > CodeForge HTML</ h3 >
124+ </ div >
125+
126+ <!-- 基本输出示例 -->
127+ < div class ="section ">
128+ < h3 > ✅ 基本输出 (Basic Output)</ h3 >
129+ < div class ="output ">
130+ < div > ✅ HTML 运行成功! (HTML is working!)</ div >
131+ < div > 🌐 这是 HTML 程序 (This is HTML program)</ div >
132+ </ div >
133+ </ div >
134+
135+ <!-- 变量操作 -->
136+ < div class ="section ">
137+ < h3 > 🔢 简单计算 (Simple Calculation)</ h3 >
138+ < div class ="button-container ">
139+ < button class ="btn " onclick ="performCalculation() "> 执行计算 / Execute Calculation</ button >
140+ </ div >
141+ < div class ="output " id ="calculationOutput "> 点击按钮执行计算...</ div >
142+ </ div >
143+
144+ <!-- 字符串操作 -->
145+ < div class ="section ">
146+ < h3 > 📝 字符串操作 (String Operations)</ h3 >
147+ < div class ="output " id ="stringOutput ">
148+ < div > 平台名称 (Platform): < span id ="platformName "> CodeForge</ span > </ div >
149+ < div > 语言版本 (Language): < span id ="languageVersion "> HTML</ span > </ div >
150+ < div > 完整信息 (Full info): < span id ="fullInfo "> CodeForge - HTML</ span > </ div >
151+ </ div >
152+ </ div >
153+
154+ <!-- 循环示例 -->
155+ < div class ="section ">
156+ < h3 > 🔄 循环输出 (Loop Output)</ h3 >
157+ < div class ="button-container ">
158+ < button class ="btn " onclick ="showLoop() "> 显示循环 / Show Loop</ button >
159+ </ div >
160+ < div class ="output " id ="loopOutput "> 点击按钮显示循环输出...</ div >
161+ </ div >
162+
163+ <!-- 数组操作 -->
164+ < div class ="section ">
165+ < h3 > 🍎 水果列表 (Fruit List)</ h3 >
166+ < ul class ="fruit-list " id ="fruitList ">
167+ < li > 1. 苹果 🍎</ li >
168+ < li > 2. 香蕉 🍌</ li >
169+ < li > 3. 橙子 🍊</ li >
170+ < li > 4. 葡萄 🍇</ li >
171+ </ ul >
172+ </ div >
173+
174+ <!-- 条件判断 -->
175+ < div class ="section ">
176+ < h3 > 📊 成绩评估 (Score Evaluation)</ h3 >
177+ < div class ="button-container ">
178+ < input type ="number " id ="scoreInput " value ="85 " min ="0 " max ="100 " style ="padding: 8px; margin: 5px; ">
179+ < button class ="btn " onclick ="evaluateScore() "> 评估成绩 / Evaluate Score</ button >
180+ </ div >
181+ < div class ="score-display good " id ="scoreResult ">
182+ 当前成绩: 85 分 - 良好! (Good!)
183+ </ div >
184+ </ div >
185+
186+ <!-- DOM操作示例 -->
187+ < div class ="section ">
188+ < h3 > 🔍 DOM操作示例 (DOM Manipulation Example)</ h3 >
189+ < div class ="button-container ">
190+ < button class ="btn " onclick ="demonstrateDOM() "> 演示DOM操作 / Demonstrate DOM</ button >
191+ </ div >
192+ < div class ="output " id ="domOutput "> 点击按钮查看DOM操作...</ div >
193+ </ div >
194+
195+ <!-- 函数示例 -->
196+ < div class ="section ">
197+ < h3 > 🎭 函数示例 (Function Example)</ h3 >
198+ < div class ="button-container ">
199+ < input type ="text " id ="userNameInput " placeholder ="请输入您的姓名... " style ="padding: 8px; margin: 5px; width: 200px; ">
200+ < button class ="btn " onclick ="greetUser() "> 问候用户 / Greet User</ button >
201+ </ div >
202+ < div class ="output " id ="greetingOutput "> 输入姓名后点击按钮...</ div >
203+ </ div >
204+
205+ <!-- 结束信息 -->
206+ < div class ="section " style ="text-align: center; background: #e8f5e8; ">
207+ < h3 > 🎯 CodeForge HTML 代码执行完成!</ h3 >
208+ < h4 > 🎯 CodeForge HTML execution completed!</ h4 >
209+ < p > 感谢使用 CodeForge 代码执行环境! 🚀</ p >
210+ < p > Thank you for using CodeForge! 🚀</ p >
211+ </ div >
212+ </ div >
213+
214+ < script >
215+ // 简单计算函数
216+ function performCalculation ( ) {
217+ const number1 = 10 ;
218+ const number2 = 20 ;
219+ const result = number1 + number2 ;
220+
221+ document . getElementById ( 'calculationOutput' ) . innerHTML =
222+ `${ number1 } + ${ number2 } = ${ result } ` ;
223+ }
224+
225+ // 循环输出函数
226+ function showLoop ( ) {
227+ let output = '' ;
228+ for ( let i = 1 ; i <= 5 ; i ++ ) {
229+ output += `第 ${ i } 次输出 (Output #${ i } ): Hello from CodeForge!<br>` ;
230+ }
231+ document . getElementById ( 'loopOutput' ) . innerHTML = output ;
232+ }
233+
234+ // 成绩评估函数
235+ function evaluateScore ( ) {
236+ const score = parseInt ( document . getElementById ( 'scoreInput' ) . value ) ;
237+ const resultDiv = document . getElementById ( 'scoreResult' ) ;
238+
239+ let evaluation = '' ;
240+ let className = '' ;
241+
242+ if ( score >= 90 ) {
243+ evaluation = '优秀! (Excellent!)' ;
244+ className = 'excellent' ;
245+ }
246+ else if ( score >= 80 ) {
247+ evaluation = '良好! (Good!)' ;
248+ className = 'good' ;
249+ }
250+ else if ( score >= 60 ) {
251+ evaluation = '及格 (Pass)' ;
252+ className = 'pass' ;
253+ }
254+ else {
255+ evaluation = '需要努力 (Need improvement)' ;
256+ className = 'improvement' ;
257+ }
258+
259+ resultDiv . textContent = `当前成绩: ${ score } 分 - ${ evaluation } ` ;
260+ resultDiv . className = `score-display ${ className } ` ;
261+ }
262+
263+ // DOM操作演示
264+ function demonstrateDOM ( ) {
265+ const now = new Date ( ) ;
266+ const element = document . getElementById ( 'domOutput' ) ;
267+
268+ const output = `
269+ <div>当前时间: ${ now . toLocaleString ( ) } </div>
270+ <div>页面标题: ${ document . title } </div>
271+ <div>用户代理: ${ navigator . userAgent . substring ( 0 , 50 ) } ...</div>
272+ <div>页面URL: ${ window . location . href } </div>
273+ ` ;
274+
275+ element . innerHTML = output ;
276+ }
277+
278+ // 问候用户函数
279+ function greetUser ( ) {
280+ const userName = document . getElementById ( 'userNameInput' ) . value || 'CodeForge用户' ;
281+ const greeting = `Hello, ${ userName } ! 👋<br>欢迎来到 CodeForge HTML 环境!` ;
282+
283+ document . getElementById ( 'greetingOutput' ) . innerHTML = greeting ;
284+ }
285+
286+ // 页面加载完成后的初始化
287+ window . onload = function ( ) {
288+ console . log ( '🎉 CodeForge HTML 环境已就绪!' ) ;
289+ console . log ( 'Welcome to CodeForge HTML Environment!' ) ;
290+ } ;
291+ </ script >
292+ </ body >
293+ </ html >
0 commit comments