//手机数字限字
手机号码:<input type="text" id="txtPhoneNumber" value="" />
<script type="text/javascript">
var oTxt = document.getElementById(‘txtPhoneNumber‘);
oTxt.onblur = function () {
var num = this.value;
if (isNaN(num) || num.length != 11) {
alert(‘手机号码长度不正确‘);
}
else {
var prefix = num.substring(0, 2);
if (prefix == "13"
|| prefix == "15"
|| prefix == "17"
||prefix=="18"
) {
alert("手机号码类型正确");
} else
{
alert("你输入的手机号码有误");
}
}
}
</script>
//获得当前时间
<a id="demo" href="#">显示当前日期</a>
<span id="date"></span>
<script type="text/javascript">
var lnk = document.getElementById(‘demo‘);
var oSpan = document.getElementById(‘date‘);
lnk.onclick = function () {
oSpan.innerHTML = new Date().toLocaleString();
if(e &&e.preventDefault){
e.preventDefault();
}else
{
window.event.returnValue = false;
}
}
</script>
//select下拉框
<script type="text/javascript">
//写法1
var displayArr = [‘苹果‘, ‘香蕉‘, ‘绿树‘, ‘狗狗‘];
//方法2
var valueArr = [];
valueArr.push(‘apple‘);
valueArr.push(‘banana‘); //push=List.Add();
valueArr.push(‘dog‘);
valueArr.push(‘tree‘);
document.write("<select>")
for (var i = 0; i < 4; i++) {
document.write(
"<option >value=‘" + valueArr[i] + "‘>"
+ displayArr[i]
+"</option>");
}
document.write("</select>");
</script>
</body>