<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/htmlcharset=UTF-8">
</head>
<body>
<input onblur="text()" id="text" type="text">
<script type="text/javascript">
function text(){
var string1 = document.getElementById('text')
var string2 = string1.value.indexOf('http://')
if(string2 != 0)
{
alert('你输入的网址不正确')
return false
}
else alert('合法')
}
</script>
</body>
</html>
<!-- 试试,是这样的效果吗? -->
很简单,看代码:<input name="" type="text" id="url" onblur="url(this)" value="" />
<script type="text/javascript">
function url(obj){
var path = obj.value
if( path == '' )
return
if( path.slice(0,7) == 'http://' )
path = path.slice(7)
path = path.split('/')
path = path[0]
obj.value= path
}
</script>
这个是鼠标失去聚焦,就判断。、