.prop()与.attr()
因此, jQuery 1.6具有新的功能 prop() 。 $(selector).click(function(){ //instead of: this.getAttribute('style'); //do i use: $(this).prop('style'); //or: $(this).attr('style'); }) 还是在这种情况下他们做同样的事情? 如果我 确实 必须切换到使用 prop() ,那么如果我切换到1.6,所有旧的 attr() 调用都会中断? 更新 selector = '#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=