Category: jQuery

การใช้ jquery หลาย เวอรชั่นรวมกันอาจจะเจอ error Uncaught TypeError: $(…)

การใช้ jquery หลาย เวอรชั่นรวมกันอาจจะเจอ error Uncaught TypeError: $(…)  เช่นการใช้ datepicker เนื่องจากบางครั้งเรา copy datepicker มาใช้แล้วมันเรียก jqeury version ที่มัน support แต่ดันมีการเรียนใช้ jqeury ก่อนหน้านี้และคนละ version ทำให้ฟังก์ชันบางอย่างไม่เหมือนกันเลยเกิด error ดังภาพ จะดังเกตุว่ามีการเรียกใช้ jqeury.mi.js และ jquery-1.4.4.min.js แล้วพอใช้…

jQuery Validate

ไฟล์ index.html ใส่ฟอร์ม <!doctype html> <html lang="en"> <head> <script type="text/javascript" src="jquery-1.7.1.min.js"></script> <script type="text/javascript" src="myscript.js"></script> <script type="text/javascript" src="jquery.validate.min.js"></script> <script type="text/javascript" src="jQueryPlugin.js"></script> </head> <body> <div id="info"><form id="commentForm" action=""> <input type="text" id="hello" value=""…

jQuery สร้าง Plugin function ใช้เอง

/// <reference path="jquery-1.7.1.min.js" /> (function ($) { //สร้างชื่อฟังชั่นไว้ใช้งานเอง $.fn.myhightlight = function () { return this.each(function(){ $(this).css('background-color','#aa0000') }); } })(jQuery) เอาไปใช้กับไฟล์ MyScript.js /// <reference path="jquery-1.7.1.min.js" /> /// <reference path="jQueryPlugin.js" /> $(document).ready(function…