javascript - jQuery中可以獲取到圖片的高度卻無法獲取寬度
問題描述
$(document).ready(function() {
ko.validation.init({ errorElementClass: ’has-error’, insertMessages : true});ko.validation.registerExtenders();var dataUrl = {imgUrl : ’/api/advertise/advertisepost’ }, loopPictures = $('.loopPictures'), buttons = $('.buttons'), imgYS = loopPictures.find('img'), imgWidth = imgYS.css('width'), imgHeight = imgYS.css('height'), kick = buttons.find('span');console.log(imgWidth); console.log(imgHeight);
問題解答
回答1:你這是 獲取style 樣式 height , 你在CSS 里面沒有設置 就肯定沒有的, 你可以用document.getElementsByClassName('class')[0].offsetHeight 獲取,或者直接用jquery $('.class').height()
相關文章:
1. python - Pycharm的Debug用不了2. 安全性測試 - nodejs中如何防mySQL注入3. Python中使用超長的List導致內存占用過大4. javascript - axios請求回來的數據組件無法進行綁定渲染5. python - pandas按照列A和列B分組,將列C求平均數,怎樣才能生成一個列A,B,C的dataframe6. javascript - 有適合開發手機端Html5網頁小游戲的前端框架嗎?7. javascript - JS變量被清空8. java - 在用戶不登錄的情況下,用戶如何添加保存到購物車?9. javascript - 關于apply()與call()的問題10. html - eclipse 標簽錯誤
