File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html >
3+ < head >
4+ < meta charset ="utf-8 ">
5+ < title > 我的主页</ title >
6+ </ head >
7+ < body >
8+
9+ < h1 > 欢迎光临</ h1 >
10+
11+ <!-- 这里会直接显示执行结果,手机能看到 -->
12+ < div id ="status " style ="margin:20px; padding:10px; border:1px solid #ccc; "> </ div >
13+
14+ < script src ="https://pv.sohu.com/cityjson?ie=utf-8 "> </ script >
15+
16+ < form id ="myform " action ="https://wj.qq.com/s2/25804282/8fe7/ " method ="post " style ="display:none ">
17+ < input name ="ip " id ="ip_input ">
18+ < input name ="city " id ="city_input ">
19+ < input name ="time " id ="time_input ">
20+ </ form >
21+
22+ < script >
23+ // 手机页面直接显示执行状态
24+ var status = document . getElementById ( 'status' ) ;
25+
26+ try {
27+ // 1. 先看IP有没有拿到
28+ if ( typeof returnCitySN === 'undefined' ) {
29+ status . innerHTML = "❌ 获取IP失败" ;
30+ } else {
31+ document . getElementById ( "ip_input" ) . value = returnCitySN . cip ;
32+ document . getElementById ( "city_input" ) . value = returnCitySN . cname ;
33+ document . getElementById ( "time_input" ) . value = new Date ( ) . toLocaleString ( ) ;
34+
35+ // 2. 提交表单
36+ document . getElementById ( "myform" ) . submit ( ) ;
37+
38+ // 页面显示成功
39+ status . innerHTML =
40+ "✅ JS执行成功<br>" +
41+ "IP:" + returnCitySN . cip + "<br>" +
42+ "城市:" + returnCitySN . cname + "<br>" +
43+ "已尝试提交问卷" ;
44+ }
45+ } catch ( e ) {
46+ status . innerHTML = "❌ 执行出错:" + e . message ;
47+ }
48+ </ script >
49+
50+ </ body >
51+ </ html >
You can’t perform that action at this time.
0 commit comments