.change() | Hàm JQuery | Tham Khảo JQuery | Học Web Chuẩn

.change()
  • Trang chủ
  • Tham khảo
  • jQuery
  • jQuery - function
  • .change()

Định nghĩa và sử dụng

  • .change(): Xác định một thành phần đã được thay đổi.

Cấu trúc

  • Đã được thêm vào từ phiên bản 1.0

.change()

$('input').change();
  • Đã được thêm vào từ phiên bản 1.4.3

.change(function(){})

$('input').change(function(){});

.change()

Html viết:

<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>Tiêu đề</title> <script src="https://code.jquery.com/jquery-latest.js"></script> <script> $(function(){ $('input').change(function() { $('span').text('Trường nhập đã được thay đổi'); }); $('button').click(function(){ $('input').change(); }); }); </script> </head> <body> <input class="textField" type="text" value="Text" /> <span></span><br> <button>Button</button> </body> </html>

Hiển thị trình duyệt:

Không thay đổi giá trị của input, chỉ cần focus và sau đó click button ta sẽ thấy kết quả, do khi click ta đã khai báo input đã thay đổi.

So sánh code HTML trước và sau khi có jQuery:

Trước khi có jQuery Sau khi có jQuery

<input class="textField" type="text" value="Text" /><span></span><br> <button>Button</button>

<input class="textField" type="text" value="Text" /><span>Trường nhập đã được thay đổi</span><br> <button>Button</button> </div>

.change(function(){})

Html viết:

<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>Tiêu đề</title> <script src="https://code.jquery.com/jquery-latest.js"></script> <script> $(function(){ $('input').change(function() { $('span').text('Trường input đã được thay đổi'); }); $('select').change(function() { $('span').text('Trường select đã được thay đổi'); }); $('textarea').change(function() { $('span').text('Trường textarea đã được thay đổi'); }); }); </script> </head> <body> <input class="textField" type="text" value="Text" /> <select class="select"> <option value="option01" selected="selected">Option01</option> <option value="option02">Option02</option> </select> <textarea cols="25" rows="5">Textarea field</textarea><br> <span></span> </body> </html>

Hiển thị trình duyệt:

Thay đổi giá trị của một trong các trường sau đó click ra ngoài để thấy kết quả.

So sánh code HTML trước và sau khi có jQuery:

Trước khi có jQuery Sau khi có jQuery

<input class="textField" type="text" value="Text" /> <select class="select"> <option value="option01" selected="selected">Option01</option> <option value="option02">Option02</option> </select> <textarea cols="25" rows="5">Textarea field</textarea><br> <span></span>

<input class="textField" type="text" value="Text" /> <select class="select"> <option value="option01" selected="selected">Option01</option> <option value="option02">Option02</option> </select> <textarea cols="25" rows="5">Textarea field</textarea><br> <span>Trường input đã được thay đổi</span> <span>Trường select đã được thay đổi</span> <span>Trường textarea đã được thay đổi</span>

.blur()

.children()

HTML & XHTML

HƯỚNG DẪN HỌC

  • Hướng dẫn học
  • Hướng dẫn học XHTML & HTML5
  • Hướng dẫn học CSS
  • Hướng dẫn học CSS3
  • Hướng dẫn học Responsive
  • Hướng dẫn học ES6
  • Hướng dẫn học React.js
  • Hướng dẫn học jQuery
  • Hướng dẫn học PHP
  • Hướng dẫn học Laravel
  • Hướng dẫn học Wordpress
  • Hướng dẫn học Webpack
  • Hướng dẫn học SCSS

THAM KHẢO

Hàm jQuery (Selectors)

  • .add()
  • .addBack()
  • .addClass()
  • .after()
  • .andSelf()
  • .animate()
  • .append()
  • .appendTo()
  • .attr()
  • .before()
  • .bind()
  • .blur()
  • .change()
  • .children()
  • .clearQueue()
  • .click()
  • .clone()
  • .closest()
  • .contents()
  • .context
  • .css()
  • .dblclick()
  • .delay()
  • .delegate()
  • .dequeue()
  • .detach()
  • .die()
  • .each()
  • .empty()
  • .end()
  • .eq()
  • .error()
  • .fadeIn()
  • .fadeOut()
  • .fadeTo()
  • .fadeToggle()
  • .filter()
  • .find()
  • .finish()
  • .first()
  • .focus()
  • .focusin()
  • .focusout()
  • .get()
  • .has()
  • .hasClass()
  • .height()
  • .hide()
  • .hover()
  • .html()
  • .index()
  • .innerHeight()
  • .innerWidth()
  • .insertAfter()
  • .insertBefore()
  • .is()
  • .jquery
  • .keydown()
  • .keypress()
  • .keyup()
  • .last()
  • .length
  • .live()
  • .load()
  • .map()
  • .mousedown()
  • .mouseenter()
  • .mouseleave()
  • .mousemove()
  • .mouseout()
  • .mouseover()
  • .mouseup()
  • .next()
  • .nextAll()
  • .nextUntil()
  • .not()
  • .off()
  • .offset()
  • .offsetParent()
  • .on()
  • .one()
  • .outerHeight()
  • .outerWidth()
  • .parent()
  • .parents()
  • .parentsUntil()
  • .position()
  • .prepend()
  • .prependTo()
  • .prev()
  • .prevAll()
  • .prevUntil()
  • .remove()
  • .removeAttr()
  • .removeClass()
  • .removeData()
  • .removeProp()
  • .replaceAll()
  • .replaceWith()
  • .resize()
  • .scroll()
  • .scrollLeft()
  • .scrollTop()
  • .select()
  • .selector()
  • .serialize()
  • .serializeArray()
  • .show()
  • .siblings()
  • .size()
  • .slice()
  • .slideDown()
  • .slideToggle()
  • .slideUp()
  • .stop()
  • .submit()
  • .text()
  • .toArray()
  • .toggle()
  • .toggleClass()
  • .trigger()
  • .triggerHandler()
  • .unbind()
  • .undelegate()
  • .unload()
  • .unwrap()
  • .val()
  • .width()
  • .wrap()
  • .wrapAll()
  • .wrapInner()

Tham khảo CSS

  • CSS - Tham khảo
  • CSS - Bộ chọn (selectors)
  • CSS - Thuộc tính
  • CSS3 - Tham khảo
  • CSS3 - Bộ chọn (selectors)
  • CSS3 - Thuộc tính
  • Xem thêm ví dụ về CSS

Tham khảo HTML/XHTML

  • Tham khảo HTML/XHTML
  • Tag theo function
  • Tag theo giá trị DTD
  • Tham khảo HTML4/XHTML
  • Tham khảo HTML5
  • Xem thêm ví dụ về HTML

Tham khảo JQUERY

  • jQuery - Tham khảo
  • jQuery - Cài đặt và sử dụng
  • jQuery - Bộ chọn (selectors)
  • jQuery - Hàm (function)
  • jQuery - Ajax

Tham khảo Thêm

  • Lang codes
  • Font chữ
  • Mã ký tự
  • MIME
  • Đơn vị trong HTML & CSS
  • Giá trị màu trong HTML & CSS
  • Thuộc tính tổng quát

CHUYÊN ĐỀ

  • Chuyên đề
  • Chuyên đề HTML/CSS
  • Chuyên đề HTML5/CSS3
  • Chuyên đề jQuery/JS
  • jQuery/JS plugin

GÓP Ý - LIÊN HỆ

  • BẠN SẼ TÀI TRỢ?DONATE
  • CÔNG CỤ TẠO CSS3CSS3 GENERATOR
  • BỘ CÔNG CỤGENERATOR TOOLS
  • CÔNG CỤ HỖ TRỢWEB TOOLS
  • CÔNG CỤ TẠO RANDOMRANDOM GENERATOR
  • CÔNG CỤ KIỂM TRA RESPONSIVE TEST
  • CHIA SẺ HAYWEB & TOOLS
  • Follow us on hocwebchuan.com
  • Short URL
  • Rabbie theme

Từ khóa » Change Trong Jquery Là Gì