.prop()vs .attr()所以jQuery 1.6具有新功能prop()。$(selector).click(function(){
//instead of:
this.getAttribute('style');
//do i use:
$(this).prop('style');
//or:
$(this).attr('style');})或者在這種情況下,他們做同樣的事情?如果我也有轉用prop(),所有的舊attr()電話,如果我切換到1.6將打破?UPDATEselector = '#id'$(selector).click(function() { //instead of: var getAtt = this.getAttribute('style'); //do i use: var thisProp = $(this).prop('style'); //or: var thisAttr = $(this).attr('style'); console.log(getAtt, thisProp, thisAttr);});<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script><div id='id' style="color: red;background: orange;">test</div>控制臺會記錄getAttribute作為一個字符串,并attr作為一個字符串,但prop作為一個CSSStyleDeclaration,為什么?這對我未來的編碼有何影響?
.prop()vs .attr()
慕虎7371278
2019-05-21 13:59:36