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. 請教使用PDO連接MSSQL數據庫插入是亂碼問題?2. node.js - nodejs開發中常用的連接mysql的庫3. Python爬蟲如何爬取span和span中間的內容并分別存入字典里?4. mysql - 分庫分表、分區、讀寫分離 這些都是用在什么場景下 ,會帶來哪些效率或者其他方面的好處5. 視頻文件不能播放,怎么辦?6. python - 數據與循環次數對應不上7. mysql - 把一個表中的數據count更新到另一個表里?8. 黑客 - Python模塊安全權限9. flask - python web中如何共享登錄狀態?10. mysql 查詢身份證號字段值有效的數據
