2017년 12월 9일 토요일

javascript memo list1

https://www.javatpoint.com/javascript-form-validation#email


<script>
  document.getElementById("demo").innerHTML = "My First JavaScript";
</script>

<script type="text/javascript">
  document.write("JavaScript is a simple language for javatpoint learners");
</script>

for (i=1; i<=5; i++)
{
  document.write(i + "<br/>")
}

var i=11;
while (i<=15)
{
  document.write(i + "<br/>");
  i++;
}

var i=21;
do{
   document.write(i + "<br/>");
   i++;
}while (i<=25);

var a=20;
if(a==10){
  document.write("a is equal to 10");
}
else if(a==15){
  document.write("a is equal to 15");
}
else if(a==20){
  document.write("a is equal to 20");
}
else{
  document.write("a is not equal to 10, 15 or 20");
}

var s1="javascript ";
var s2="concat example";
var s3=s1.concat(s2);
document.write(s3);

var s1="     javascript trim    ";
var s2=s1.trim();
document.write(s2);

var s1="abcdefgh";
var s2=s1.slice(2,5);
document.write(s2);

var s1="JavaScript toUpperCase Example";
var s2=s1.toUpperCase();
document.write(s2);

var s1="JavaScript toLowerCase Example";
var s2=s1.toLowerCase();
document.write(s2);

var s1="javascript from javatpoint indexof";
var n=s1.lastIndexOf("java");
document.write(n);

var s1="javascript from javatpoint indexof";
var n=s1.indexOf("from");
document.write(n);

var str="javascript";
document.write(str.charAt(2));

var stringname=new String("hello javascript string");
document.write(stringname);

object={property1:value1,property2:value2.....propertyN:valueN}
emp={id:102,name:"Shyam Kumar",salary:40000}
document.write(emp.id+" "+emp.name+" "+emp.salary);

var emp=new Object();
emp.id=101;
emp.name="Ravi Malik";
emp.salary=50000;
document.write(emp.id+" "+emp.name+" "+emp.salary);

function emp(id,name,salary){
  this.id=id;
  this.name=name;
  this.salary=salary;
}
e=new emp(103,"Vimal Jaiswal",30000);
 
document.write(e.id+" "+e.name+" "+e.salary);

function emp(id,name,salary){
  this.id=id;
  this.name=name;
  this.salary=salary;
 
  this.changeSalary=changeSalary;
   
  function changeSalary(otherSalary){
    this.salary=otherSalary;
  }
}
e=new emp(103,"Sonoo Jaiswal",30000);
document.write(e.id+" "+e.name+" "+e.salary);
e.changeSalary(45000);
document.write("<br>"+e.id+" "+e.name+" "+e.salary);

var emp=["Sonoo","Vimal","Ratan"];
for (i=0;i<emp.length;i++){
   document.write(emp[i] + "<br/>");
}

var i;
var emp = new Array();
emp[0] = "Arun";
emp[1] = "Varun";
emp[2] = "John";
 
for (i=0;i<emp.length;i++){
  document.write(emp[i] + "<br>");
}

var emp=new Array("Jai","Vijay","Smith");
for (i=0;i<emp.length;i++){
  document.write(emp[i] + "<br>");
}

Current Date and Time: <span id="txt"></span>
var today=new Date();
document.getElementById('txt').innerHTML=today;
Current Date and Time: Sun Dec 10 2017 09:59:52 GMT+0900 (JST)

var date=new Date();
var day=date.getDate();
var month=date.getMonth()+1;
var year=date.getFullYear();
document.write("<br>Date is: "+day+"/"+month+"/"+year);
Date is: 10/12/2017


Current Time: <span id="txt"></span>
<script>
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
document.getElementById('txt').innerHTML=h+":"+m+":"+s;
</script>
Current Time: 9:59:52

Events Description
onclick occurs when element is clicked.
ondblclick occurs when element is double-clicked.
onfocus occurs when an element gets focus such as button, input, textarea etc.
onblur occurs when form looses the focus from an element.
onsubmit occurs when form is submitted.
onmouseover occurs when mouse is moved over an element.
onmouseout occurs when mouse is moved out from an element (after moved over).
onmousedown occurs when mouse button is pressed over an element.
onmouseup occurs when mouse is released from an element (after mouse is pressed).
onload occurs when document, object or frameset is loaded.
onunload occurs when body or frameset is unloaded.
onscroll occurs when document is scrolled.
onresized occurs when document is resized.
onreset occurs when form is reset.
onkeydown occurs when key is being pressed.
onkeypress occurs when user presses the key.
onkeyup occurs when key is released.


Method Description
alert() displays the alert box containing message with ok button.
confirm() displays the confirm dialog box containing message with ok and cancel
button.
prompt() displays a dialog box to get input from the user.
open() opens the new window.
close() closes the current window.
setTimeout() performs action after specified time like calling function, evaluating
  expressions etc.

var n=new Number(value);
var x=102;//integer value
var y=102.7;//floating point value
var z=13e4;//exponent value, output: 130000
var n=new Number(16);//integer value by number object

Constant Description
MIN_VALUE returns the largest minimum value.
MAX_VALUE returns the largest maximum value.
POSITIVE_INFINITY returns positive infinity, overflow value.
NEGATIVE_INFINITY returns negative infinity, overflow value.
NaN represents "Not a Number" value.

JavaScript Number Methods

Let's see the list of JavaScript number methods with description.

Methods Description
toExponential(x) displays exponential value.
toFixed(x) limits the number of digits after decimal value.
toPrecision(x) formats the number with given number of digits.
toString() converts number into string.
valueOf() coverts other type of value into number.


document.writeln("<br/>screen.width: "+screen.width);
document.writeln("<br/>screen.height: "+screen.height);
document.writeln("<br/>screen.availWidth: "+screen.availWidth);
document.writeln("<br/>screen.availHeight: "+screen.availHeight);
document.writeln("<br/>screen.colorDepth: "+screen.colorDepth);
document.writeln("<br/>screen.pixelDepth: "+screen.pixelDepth);

var number=document.getElementById("number").value;
var allgenders=document.getElementsByName("gender");
var totalpara=document.getElementsByTagName("p");

function showcommentform() {
var data="Name:<input type='text' name='name'><br>Comment:<br><textarea rows='5' cols='80'></textarea>
<br><input type='submit' value='Post Comment'>";
document.getElementById('mylocation').innerHTML=data;
}


댓글 없음:

댓글 쓰기