-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
123 lines (114 loc) · 3.25 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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>inurl.cn-短网址生成服务</title>
<style>
*{margin:0;padding:0;}
textarea{resize:none;}
input,input:focus,textarea,textarea:focus{outline:none;border:none;}
body{font-size:16px;font-family:"Microsoft Yahei","宋体",arial;}
.bd-wrap{width:720px;margin:30px auto;}
.placeholder-box{position:relative;}
.placeholder{position:absolute;left:0;top:0;line-height:22px;padding:6px;font-size:12px;color:#777;text-indent:10px;}
.placeholder:focus{}
.add-url{border:1px solid #8cc665;line-height:22px;padding:6px;width:706px;text-indent:10px;}
.add-url:focus{border:1px solid #44a340;}
.shorten{
line-height:24px;
padding:6px 12px;
display:inline-block;
color:#fff;
background:#44a340;
cursor:pointer;
font-size:16px;
vertical-align:top;
}
.shorten-box{
text-align:right;
}
</style>
</head>
<body>
<div id="hd">
<div id="logo-box"></div>
</div>
<div id="bd" class="bd-wrap">
<div id="url-box" class="url-box">
<h1>网址缩短</h1>
<div id="placeholder-box" class="placeholder-box">
<textarea name="addurl" id="J-add-url" class="add-url" cols="30" rows="10"></textarea>
<span class="placeholder" id="J-placeholder">请输入http://或https://开头的网址</span>
</div>
<div id="shorten-box" class="shorten-box">
<input type="submit" class="shorten" id="J-shorten" value="生成网址">
</div>
</div>
</div>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script>
$(function(){
var placeholder=$('#J-placeholder');
var url=$('#J-add-url');
$('#J-placeholder').on('click',function(){
$(this).hide();
});
$('#J-add-url').on({
'focus':function(){
$('#J-placeholder').hide();
},
'blur':function(){
var _val=$(this).val();
if(_val==''){
$('#J-placeholder').show();
}else{
$('#J-placeholder').hide();
}
}
});
$('#J-shorten').on('click',function(){
//
var val=$('#J-add-url').val();
var _val=$.trim(val);
//空白
var whiteReg=/^\s+$/;
//网址正则
var strRegex="^((https|http|ftp|rtsp|mms)?://)"
+ "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" // ftp的user@
+ "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184
+ "|" // 允许IP和DOMAIN(域名)
+ "([0-9a-z_!~*'()-]+\.)*" // 域名- www.
+ "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 二级域名
+ "[a-z]{2,6})" // first level domain- .com or .museum
+ "(:[0-9]{1,4})?" // 端口- :80
+ "((/?)|" // a slash isn't required if there is no file name
+ "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$";
var urlRegex=new RegExp(strRegex);
if(whiteReg.test(val)){
alert('请输入网址')
return false;
}
if(!urlRegex.test(_val)){
alert('抱歉,您输入的网址不符合规范,请检查后重新输入!');
}else{
//发送请求
$.ajax({
url:'/addurl/',
dataType:'json',
data:{
url:_val
},
cache:false,
success:function(data){
alert(data);
},
error:function(){
alert('网络错误,请稍后重试!');
}
});
}
});
});
</script>
</body>
</html>