Skip to main content

Posts

Tên, tuổi, lời chào - JavaScript - Ngày 6

Untitled Document Tên: : Năm sinh: //Code <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> <style> #abc{color: red; font-weight: bold;} </style> </head> <body> <script type="text/javascript"> function chao(ts1, ts2) { ngay=new Date(); namht=ngay.getFullYear(); alert(namht); tuoi=namht-parseInt(ts2); document.getElementById("kq").innerHTML="Chào bạn <span id='abc'>"+ts1+"</span>. Hiện nay bạn đang "+tuoi+" tuổi"; } </script> <form id="form1" name="form1" method="post">   <p>     <label for="ten">Tên: :</label>     <input type="text" name="ten" id="ten">   </p>   <p>     <label for="namsinh">...

JavaScript - Kiểm tra form flogin - Kiểm tra form search - Dò độ phân giải

LAB JAVASCRIPT

LAB JAVASCRIPT 1.      Kiểm tra form flogin -         Tạo form   như sau: . // File login.html <form id="flogin" name="flogin" method="post" action="xulylogin.html"> Username:<br/> <input name="u" id="u" type="text" /> <br/> Password:<br/> <input name="p" id="p" type="password"/> <br/> <input type="submit" name="sub" id="sub" value="Login" /> </form>   -         Tạo file javaScript checklogin.js function checklogin (){      if ( document. flogin.u.value==''){            alert(" Bạn chưa nhập username ");            document. flogin.u. focus(); //Chọn đối tượng u           return false;    // Chặn form không cho ...

Bài tập 3 - tạo bảng màu

Untitled Document Số dòng: Số cột: Chọn màu:: Xanh dương Đỏ Vàng //Code <html> <head> <meta charset="utf-8"></meta> <title>Untitled Document</title> </head> <body> <script type="text/javascript"> function tbang(ts1,ts2,ts3) { tam="<table border='1' width='80%' bgcolor='"+ts3+"'>"; for(i=1;i<=ts1;i++) { tam+="<tr>"; //là phép gán rút gọn của: tam=tam+"<tr>"; for(j=1;j<=ts2;j++) tam+="<td>&nbsp;</td>"; tam+="</tr>"; } tam+="</table>"; document.getElementById("kq").innerHTML=tam; } </script> <form id="form1" method="post" name="form1">   <p>     <label for="dong">Số dòng:</label...

Tính tổng, hiệu, tích, thương - Hàm JavaScript

Untitled Document Số 1:: Số 2:: Kết quả:: //Code <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> <script type="text/javascript"> function tong(a,b) { a=parseInt(a); b=parseInt(b); document.getElementById("kq").value=a+b; } function hieu(a,b) { a=parseInt(a); b=parseInt(b); document.getElementById("kq").value=a-b; } function tich(a,b) { a=parseInt(a); b=parseInt(b); document.getElementById("kq").value=a*b; } function thuong(a,b) { a=parseInt(a); b=parseInt(b); document.getElementById("kq").value=a/b; } </script> </head> <body> <form id="form1" name="form1" method="post">   <p>     <label for="so1">Số 1::</label>     <inp...

Bài tập 2 - Tạo bảng - Hàm Javascript

Untitled Document Số dòng: Số cột: //Code <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <script type="text/javascript"> function tbang(ts1,ts2) { tam="<table border='1' width='80%'>"; for(i=1;i<=ts1;i++) { tam+="<tr>"; //là phép gán rút gọn của: tam=tam+"<tr>"; for(j=1;j<=ts2;j++) tam+="<td>&nbsp;</td>"; tam+="</tr>"; } tam+="</table>"; document.getElementById("kq").innerHTML=tam; } </script> <form id="form1" name="form1" method="post">   <p>     <label for="dong">Số dòng:</label>     <input type="text" name="dong" id="dong"...

Bài tập 1 - tính tổng - Hàm Javascript

Untitled Document Số 1:: Số 2:: Kết quả:: _________________ <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> <script type="text/javascript"> function tong() { a=parseInt(document.getElementById("so1").value); b=parseInt(document.form1.so2.value); tam=a+b; document.getElementById("kq").value=tam; } function tong2(a,b) { a=parseInt(a); b=parseInt(b); document.getElementById("kq").value=a+b; } </script> </head> <body> <form id="form1" name="form1" method="post">   <p>     <label for="so1">Số 1::</label>     <input type="text" name="so1" id="so1">   </p>   <p>     <label for="so2">Số 2::</label>     <input type=...