search

Home  >  Q&A  >  body text

javascript - The height of the image can be obtained in jQuery but the width cannot be obtained

$(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);    
    
    
    
    
女神的闺蜜爱上我女神的闺蜜爱上我2705 days ago969

reply all(1)I'll reply

  • 代言

    代言2017-07-05 11:08:33

    You are getting the style height. If you have not set it in CSS, it will definitely not exist. You can use document.getElementsByClassName("class")[0].offsetHeight to get it,
    or directly use jquery $(".class") .height()

    reply
    0
  • Cancelreply