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. javascript - sublime快鍵鍵問題2. javascript - immutable配合react提升性能?3. Apache 已經把網站根目錄的改為allow from all了,但是服務器還是不能訪問?4. 配置Apache時,添加對PHP的支持時語法錯誤5. phpstudy8.1支持win11系統嗎?6. css - 寫頁面遇到個布局問題,求大佬們幫解答,在線等,急!~7. vue.js - Vue 如何像Angular.js watch 一樣監聽數據變化8. javascript - nodejs關于進程間發送句柄的一點疑問9. 實現bing搜索工具urlAPI提交10. javascript - 移動端上不能實現拖拽布局嗎?

網公網安備