<html>
<body>
<script type="text/javascript">
var str = "abcdefg";
document.writeln(str.substring(4)); //efg
document.writeln(str.substr(3,2)); //de
var str2 = "12px";
document.write(parseInt(str2)); //12
function DateDemo(){
var d, s="今天是:";
d= new Date();
s += d.getFullYear()+"-";
s += (d.getMonth()+1).length=1 ? "0"+(d.getMonth()+1)+"-" : (d.getMonth()+1)+"-";
s += d.getDate();
return s;
}
var str3 = DateDemo();
document.writeln(str3); //今天是:2014-08-10
</script>
</body>
</html>
js小练习
最新推荐文章于 2024-11-02 23:32:29 发布