JavaScript基础

1.在Java中,如果要引入内部对象,应该用with(),例如:

   with(Math);
   document.write(cos(PI/3));


2.JavaScript对象

  

<!doctype html>
<html>
<head>
<title>JavaScript</title>
</head>
<script>

function Person(name, num, sex){
	this.name = name;
	this.num = num;
	this.sex = sex;
	this.Show = Show;
}

function Show(){
    document.write(this.name+" "+this.num+" "+this.sex);
}

var p = new Person("Jack",10011,"man");
p.Show();

</script>
<body>
</body>
</html>

3.JavaScript日期对象

<!doctype html>
<html>
<head>
<title>JavaScript</title>
</head>
<script>

    var now  = new Date();
	year = 1900 + now.getYear();      //年
	month = 1 + now.getMonth();       //月
	date = now.getDate();             //日
	hour = now.getHours();            //时
	minute = now.getMinutes();        //分
    second = now.getSeconds();        //秒

    document.write(year+"年"+month+"月"+date+"日"+hour+"时"+minute+"分"+second+"秒");	

</script>
<body>
</body>
</html>


4.JavaScript简易计算器

<!doctype html>
<html>
    <head>
        <title>ACdreamer's calculator</title>
    </head>
    <script>

		function add()
		{
			var v1=parseInt(document.myform.text1.value);
			var v2=parseInt(document.myform.text2.value);
			document.myform.text3.value=v1+v2;
		}

		function subtract()
		{
			var v1=parseInt(document.myform.text1.value);
			var v2=parseInt(document.myform.text2.value);
			document.myform.text3.value=v1-v2;
		}

		function multiply()
		{
			var v1=parseInt(document.myform.text1.value);
			var v2=parseInt(document.myform.text2.value);
			document.myform.text3.value=v1*v2;
		}

		function divide()
		{
			var v1=parseInt(document.myform.text1.value);
			var v2=parseInt(document.myform.text2.value);
			document.myform.text3.value=v1/v2;
		}

		function ClearText()
		{
			document.myform.text1.value="";
			document.myform.text2.value="";
			document.myform.text3.value="";
		}
		
    </script>
    <body>
        <center>
            <br><br><br><br><br>
            <h2><font color="green"><strong>A Magic Calculator</strong></font></h2> 
            <h3><font color="blue">Made ACdreamer in the year of 2013.</font></h3>
           
		    <form name="myform">
     
	            <font color="red"><strong>The First    Input:</strong></font>
                <input type="text" name="text1"><br><br>
				<font color="red"><strong>The Second Input:</strong></font>
				<input type="text" name="text2"><br><br><br>
				<font color="red"><strong>Select Your Operation: </strong></font>
				<input type="button" value="+" onClick="add()">
				<input type="button" value="-" onClick="subtract()">
				<input type="button" value="*" onClick="multiply()">
				<input type="button" value="/" onClick="divide()">
				<input type="button" value="Clear" onClick="ClearText()"><br><br><br>
				<font color="red"><strong>Result Output:</strong></font>
				<input type="text" name="text3"><br>

            </form>
        </center>
    </body>
</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值