Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > jQuery > jQuery Introduction > jQuery Syntax : jQuery Basic Syntax



Clound SSD Virtual Server

jQuery Syntax : jQuery Basic Syntax

jQuery Syntax รูปแบบคำสั่งพื้นฐานของ jQuery Library Framework
jQuery การทำงานส่วนมากใน Web Form จะให้ความสำคัญในการอ้างถึง (Selectors) element ในรูปแบบต่าง ๆ หากจะเข้าใจง่าย ๆ ในระบบการเขียน JavaScript แบบดังเดิมจะใช้ document.form.element หรือ document.getElementById ในการอ้างถึง element เช่น

<input type="text" id="txtname">


ถ้าในระบบเดิมของ JavaScript เราจะเรียกใช้ element นี้ได้โดยการใช้คำสั่ง

document.form.txtname.value = 'myText';
document.getElementById("").value = 'myText';


แต่ใน Syntax ของ jQuery คำสั่งพวกนี้จะไม่ได้ถูกเรียกใช้อีกเลย โดย ใช้สั้น ๆ เพียง

$("#txtname").val("myText");


นอกจากนี้ jQuery ยังมีความสามารถอ้างถึง (Selectors) element ได้หลายหลายรูปแบบมาก เช่น
สามารถ Selectors จาก id="test" , แท็ก HTML ต่าง ๆ <p> <span> <div> หรือ class="test" และอื่น ๆ อีกมาก
ซึ่งสามารถศึกษาได้จากหัวข้อถัดไป

Selectors ที่พบเจอเป็นประจำ

$(this).action()
ใช้ Selectors อ้างถึง element ใน ปัจจุบัน

$("#test").action()
ใช้ Selectors อ้างถึง element ที่อยู่ภายใต้ id="test"

$("p").action()
ใช้ Selectors อ้างถึง element ที่อยู่ภายใต้ แทกทั้งหมด <p>หรือ <div> หรือ <span>

$(".test").action()
ใช้ Selectors อ้างถึง element ที่อยู่ภายใต้ แทกทั้งหมด ที่เรียกใช้ css style sheet เช่น class="test"








ตัวอย่างการใช้งาน Selectors ในการอ้างถึง element แบบง่าย ๆ

Code (jQuery)
<html>
<head>
<title>ThaiCreate.Com jQuery Tutorials</title>
<script type="text/javascript" src="jquery-1.6.4.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("#btnClick").click(function(){
  $(this).val("Hello");
  });
});
</script>
</head>
<body>
<input type="button" id="btnClick" value="Click">
</body>
</html>


Screenshot

jQuery Syntax

คำอธิบาย
จากตัวอย่างบรรทัด $("#btnClick").click(function() มีการอ้างถึง element id="btnClick" ของปุ่ม button โดยเมื่อ event มีการ click จะเปลี่ยนข้อความใน button เป็นคำว่า Hello


สำหรับการใช้งาน Selectors เบื้องต้น สามารถศึกษาได้จากหัวข้อถัดไป







.

   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2011-09-21 20:20:08 / 2017-03-19 13:14:45
  Download : No files
 Sponsored Links / Related

 
jQuery : What's a jQuery , jQuery คืออะไร ??
Rating :

 
jQuery : How to use , จะเขียน jQuery จะต้องทำอย่างไร
Rating :

 
jQuery Selectors : jQuery Selectors and Element
Rating :

 
jQuery HTML : jQuery and HTML
Rating :

 
jQuery Css : jQuery and Css
Rating :

 
jQuery Events : jQuery and Events
Rating :

 
jQuery Effects : jQuery and Effects
Rating :

 
jQuery Ajax : jQuery and Ajax
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 03
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่