使用三目运算添加个位数前的0
<script type="text/javascript">
var iText=document.getElementById("clock");
var c=setInterval(begin,100);
function begin(){
var time=new Date();
var s=time.getSeconds();
//三目运算:
var h=time.getHours();h=(h<10)?"0"+h:h;
var m=time.getMinutes();m=(m<10)?"0"+m:m;
var s=time.getSeconds();s=(s<10)?"0"+s:s;
document.getElementById("clock").value = h+":"+m+":"+s;}
</script>