/**
* js 判断的几种写法
*/
var a = 10,b = 20
console.log(a)
console.log(b)
/*最直接*/
if(a >b){
console.log('a大')
}else{
console.log('b大')
}
/*改变1*/
if(a >b) console.log('a大')
if(a <b) console.log('b大')
/*改变2*/
if(a >b) console.log('a大')
else console.log('b大')
/*最简单*/
console.log(a>b ? 'a大' : 'b大')
<html><head>
<script>
function CheckInput(){
var name = "username"
var name_v = document.getElementById(name).value
var name_c = document.getElementById(name+"_c").innerHTML
if(name_c.indexOf("*")!=-1){
if(name_v != "" &&name_v != null){
document.getElementById(name+"_m").innerHTML="恭喜您!"
}else{
document.getElementById(name+"_m").innerHTML="请正确填写!"
return false
}
}
var add= "address"
var add_v = document.getElementById(add).value
var add_c = document.getElementById(add+"_c").innerHTML
if(add_c.indexOf("*")!=-1){
if(add_v != "" &&add_v != null){
document.getElementById(add+"_m").innerHTML="恭喜您!"
}else{
document.getElementById(add+"_m").innerHTML="请正确填写!"
return false
}
}
return true
}
</script>
<head/>
<body>
<form onSubmit="return CheckInput()">
<input type="text" id="username" />
<span id="username_c">*</span>
<span id="username_m"></span>
<br />
<input type="text" id="address" />
<span id="address_c">*</span>
<span id="address_m"></span>
<br />
<input type="Submit" value="提交" />
<form>
</body>
</html>
<script>function show(){
var date = new Date()//日期对象
var now = ""
now = date.getFullYear()+"-"//读英文就行了
now = now + change((date.getMonth()+1))+"-"//取月的时候取的是当前月-1如果想取当前月+1就可以了
now = now + change(date.getDate())+" "
now = now + change(date.getHours())+":"
now = now + change(date.getMinutes())+":"
now = now + change(date.getSeconds())+""
document.getElementById("nowDiv").innerHTML = "<br/>"+now
setTimeout("show()",1000)//设置过1000毫秒就是1秒,调用show方法
}
function change(num){
if(num<10) return "0"+num
else return num
}
</script>
<div id="nowDiv">
</div>
<script>
show()
</script>
为了使代码简洁,我做了个函数
参数是数值
function change(num){
if(num<10) return "0"+num
else return num
}
如果传入的小于10则在前面加个0
否则则直接返回
我这边测试通过
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)