j查询高度和宽度无法正常工作


jQuery height and width not working properly

我有一个图像,它的宽度大于高度,它仍然使用jQuery中的第二个if语句输出。我相信这可能与输出多个图像文件的 PHP 扇区有关。所以我将 id 选择器更改为类选择器,但它不想让步。有人知道我做错了什么吗?我在这个问题上已经跌到了谷底。

<?php $userid = $this->session->userdata('userid');
      $selectedId = $_REQUEST['id'];      
      $query1 = $this->db->query("SELECT * FROM userProfilePhotos p, userProfileAlbums a WHERE p.isAlbumCover = 'Yes' AND p.userid = a.userid AND a.userid = '{$selectedId}' AND a.albumId = p.albumId");
        foreach($query1->result() as $row1) {?>
    <script type="text/javascript">
    $(document).ready(function() {
    function heightOverWidth() {
        return '<div style="width: 102px; height: 136px; border-radius: 3pt; background-color: white; border: 1px solid #C1C1C1; padding: 10pt">'+
               '<img id="profileImg" alt="" height="130" src="<?=base_url().$row1->imgURI?>" width="100" />'+
               '</div><span class="link-font3"><?=$row1->albumName?></span> <span class="font1"> - <?=$row1->albumDesc?></span>';
    }
    var img = $(".profileImg");
    if (img.width() >= img.height()) {
        alert("1");
    } if (img.height() >= img.width()) {
        $("#albumList").append(heightOverWidth());
    }
    });
    </script>
<?php list($width, $height, $type, $attr) = getimagesize(base_url() . $row1->imgURI); ?>
<div id="albumList" style="padding: 10pt">
<img class="profileImg" style="display: none" alt="" height="<?=$height?>" width="<?=$width?>" src="<?=base_url().$row1->imgURI?>" />
</div>
<?php } ?>

将 width() 更改为 attr('width'),高度也是如此。这将读取您的宽度/高度属性,而不是尝试获取实际的宽度和高度。您的解决方案不能用作具有 display:none 的元素,没有任何可见的尺寸。