Jquery 1.6+ .prop()與.attr()方法比較
今天在用JQuery的時候發現一個問題用.attr("checked")獲取checkbox的checked屬性時選中的時候可以取到值,值爲"checked"但沒選中獲取值就是undefined.
解決這個文章我參考了這個帖子:
http://bugs.jquery.com/ticket/9812
Attribute/Property | .attr() |
.prop() |
---|---|---|
accesskey | √ | |
align | √ | |
async | √ | √ |
autofocus | √ | √ |
checked | √ | √ |
class | √ | |
contenteditable | √ | |
draggable | √ | |
href | √ | |
id | √ | |
label | √ | |
location ( i.e. window.location ) | √ | √ |
multiple | √ | √ |
readOnly | √ | √ |
rel | √ | |
selected | √ | √ |
src | √ | |
tabindex | √ | |
title | √ | |
type | √ | |
width ( if needed over .width() ) |
√ |