sondmk header
เรียนรู้การเขียน JavaScript เบื้องต้น

Js : javascript call function in jQuery

Post by Goborijung at 2021-08-26 11:21:55 | ID: 1328

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
  // jQuery Function
  $(document).ready(function(){	 
    $.fOut = function(){
      window.setTimeout(function() {
        $(".alert").fadeTo(1000, 0).slideUp(1000, function(){
            $(this).remove(); 
        });
      }, 3000);
    };  	  
  });

  // Javascript Function
  function getData(id)
  {
    //alert(id);
    $.fOut(); //call function fOut in  jQuery

	  var cTime 	= document.getElementById("createdTime-"+id).value; 
	  var clTime 	= document.getElementById("closedTime-"+id).value; 

	  const xhttp = new XMLHttpRequest();
		xhttp.onload = function() {
		  document.getElementById("response-"+id).innerHTML = this.responseText;
		}
		xhttp.open("POST", "ticket_update.php");
		xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xhttp.send("ticket_number="+id+"&cTime="+cTime+"&clTime="+clTime);
  }
</script>

JS : Set Focus , setFocus

Post by Goborijung at 2022-08-03 08:30:22 | ID: 1732

document.getElementById("myAnchor").focus();



Js : ตัวหนังสือวิ่ง

Post by Goborijung at 2022-01-18 09:00:08 | ID: 1363

Ref: 
https://webblog2u.blogspot.com/2014/01/blog-post.html

<marquee direction="left" onmouseout="this.start()" onmouseover="this.stop()" scrollamount="2" scrolldelay="5">
  <span style="color: red;">
    <div>
      <b>
        พนักงานทุกแผนก สามารถเริ่มเบิกใบลา
		ผ่านระบบ ตั้งแต่เวลา 8.00 น. - 13.30 น.
  		และติดต่อขอรับใบลา ได้ในเวลา 15.00 - 15.30 น.
      </b>
    </div>
  </span>
</marquee>

JS : ตัวอย่างการเขียน Keypress , or Keyup

Post by Goborijung at 2022-07-09 12:59:32 | ID: 1689

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Arithmetic</h2>
<p>A typical arithmetic operation takes two numbers and produces a new number.</p>

oil:<br><input type='text' name='txtOil' id='txtOil'>
<br>pay:<br><input type='text' name='txtPay' id='txtPay'>
<br>cal:<br><input type='text' name='txtCal' id='txtCal' readonly>
<br>Out:<br><textarea name='mmeOut' id='mmeOut' rows="10" cols="30" readonly></textarea>

<div id='res'></div>

<script>
//let x = 100 + 50;
//document.getElementById("demo").innerHTML = x;

//document.getElementById("txtOil").onkeypress = function() {myFunction()};
document.getElementById("txtOil").onkeyup = function() {myFunction()};
document.getElementById("txtPay").onkeyup = function() {myFunction()};

function myFunction() 
{
  
 //alert('test');

 //input
 //let val = document.getElementById("idname").value;
 var oil = document.getElementById("txtOil").value; 
 var pay = document.getElementById("txtPay").value;
 var cal = "";
 var rm = 0;
 var out = "";
 
 var m500 = 0;
 var m100 = 0;
 var m50 = 0;
 var m20 = 0;
 var m10 = 0;
 var m5 = 0;
 var m1 = 0;
 
 oil = parseInt(oil);
 pay = parseInt(pay);
 
 //process
 if(pay >= oil)
 {
   //alert('ok');
   cal = pay-oil;
   rm = cal;
   
   if(rm >= 500)
   {
     m500 = Math.floor(rm/500); //Ex 255/100 = 2
     rm -= (m500*500);
     out += "b500: "+m500+" ใบ";
   }
   
   if(rm >= 100)
   {
     m100 = Math.floor(rm/100); 
     rm -= (m100*100);
     out += "b100: "+m100+" ใบ";
   }
   
   if(rm >= 50)
   {
     m50 = Math.floor(rm/50); 
     rm -= (m50*50);
     out += "b50: "+m50+" ใบ";
   }
   
   if(rm >= 20)
   {
     m20 = Math.floor(rm/20);
     rm -= (m20*20);
     out += "b20: "+m20+" ใบ";
   }
   
   if(rm >= 10)
   {
     m10 = Math.floor(rm/10);
     rm -= (m10*10);
     out += "10: "+m10+" เหรียญ";
   }
   
   if(rm >= 5)
   {
     m5 = Math.floor(rm/5);
     rm -= (m5*5);
     out += "5: "+m5+" เหรียญ";
   }
   
   if(rm >= 1)
   {
     m1 = Math.floor(rm/1);
     rm -= (m1*1);
     out += "1: "+m1+" เหรียญ";
   }
   
   out += "จบการทำงาน ขอบคุณครับ :)";
   document.getElementById('txtCal').style.backgroundColor = "lightgray";
 }

 //output
 //document.getElementById("demo").style.backgroundColor = "red";
 //document.getElementById("res").innerHTML = pay;
 document.getElementById('txtCal').value = cal;
 document.getElementById('mmeOut').value = out;
 
}

</script>

</body>
</html>

<<<12345

Framework

Library


เครื่องมือพัฒนาเว็บ



การออกแบบและพัฒนาเว็บไซต์


Download SourceCode



copyAllright © 2016 soundmk.com