Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

วิธีตั้งค่า Named Cookies ใน JavaScript

ตั้งค่า Named Cookie ด้วยโค้ดตัวอย่าง ตั้งชื่อ Customer ใน Input Cookie

ตัวอย่าง

<html> 
  <head> 
    <script> 
      function WriteCookie() { 
        if( document.myform.customer.value == "" ) { 
          alert("Enter some value!"); 
          return; 
        } 
        cookievalue = escape(document.myform.customer.value) + ";"; 
        document.cookie = "name=" + cookievalue; 
        document.write("Setting Cookies : " + "name=" + cookievalue ); 
      } 
    </script> 
  </head> 
  <body> 
    <form name="myform" action=""> 
      Enter name: <input type="text" name="customer"/> 
      <input type="button" value="Set Cookie" onclick="WriteCookie();"/> 
    </form> 
  </body> 
</html>