Home Attributes

Attributes

Truy cập thuộc tính của một phần tử - attr()

E-mail Print PDF
User Rating: / 1
PoorBest 

Phương thức attr() dùng để truy cập thuộc tính của một phần tử, chính xác là phần tử đầu tiên mà ta dùng hàm $() để chọn.

Ví dụ: 

Có 1 input text:

  1. <input type="text" name="textfield" id="textfield" value="Dau Huy" />
 

Để lấy giá trị của nó thì đơn giản như sau:

  1. $(":submit").click(function(){
  2.                     var t = $("#textfield").attr("value");
  3.                     $("#test").text(t);
  4.                     return false;
  5.                 });
 
 

Code đầy đủ:

Last Updated ( Tuesday, 22 September 2009 13:22 ) Read more...
 

Đề cử phpLemon

POLLS

Bạn thích sử dụng JavaScript Framework nào nhất?
 

Alexa Rank


Who's Online

We have 2 guests online