我有以下的HTML件:jQuery的獲得自定義(由)屬性值
<div onClick="javascript:getComments(this);" store-id="143568" class="CountryRow" style="padding: 4px;"><div class="flag flag_az"></div> Azerbaijan</div>
,我想創建一個jQuery函數來獲取的store-id
值。我有以下但它不工作:
getComments = function(input) {
fValue = $(input).val($(input).attr("store-id"));
alert('the ID :'+fValue);
}
有人可以告訴我什麼是我做錯了。
對於什麼是值得的,HTML5提供了一個像這樣的自定義屬性的標準設施。 http://ejohn.org/blog/html-5-data-attributes/ – mwilson