Zohar_lib 2020-12-26 20:05 采纳率: 68.4%
浏览 557
已结题

document.querySelector().style.left无法读取值

相关代码如下,也尝试过把position调为absolute(不知道是不是这个原因),getElementById().style.left也尝试过,用alert无法读出数据,offLeft也读取不出来

代码:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<style>
    .popup_background{background-color: #B3B3B3;position: absolute;top: 0px;right: 0px;left: 0px;bottom: 0px;-moz-opacity: 0.8;opacity:.80;filter: alpha(opacity=80);/* 只支持IE6、7、8、9 */}
    .popup{background-color: aliceblue;width: 300px;height: 230px;position: fixed;top: 0;right: 0;left: 0;bottom: 0;margin: auto;text-align: center;width:300px;border-radius:5px 5px 5px 5px;}
    .popup_text{position: relative;top: 35px;font-size: 20px; font-weight: 700;color: rgba(53,53,53,1.00);}
    .popup_buttom{position: relative;top: 60px;display: block;margin: 0 auto;width: 150px;height: 40px;color: white;background-color: rgba(227,107,109,1.00);border: 0px;border-radius: 5px;}
    .popTitle{background: #9DACBF;height: 40px;line-height: 40px;padding: 1px;border-radius:5px 5px 0px 0px;}
    .title_left{font-weight: bold;padding-left: 5px;float: left;}
    .title_right{font-weight: bold;padding-right: 5px;float: right;} 
</style>
<script type="text/javascript">
        function openPopup(){
            document.getElementById("popup_background").style.display = "block";
            document.getElementById("popup").style.display = "block";
        }
        alert(document.querySelector("popTitle").style.left);
        popTitle.onmousedown = function(e){
            x = e.clientX;
            y = e.clientY;
            alert("aha");
            l = popTitle.offsetLeft;
            t = popTitle.offsetTop;
            
            isDown = true;
            popTitle.style.cursor = 'move';
            alert("hah");
        }

</script>
<body>
        <div class="popup_background" id="popup_background"></div>
        <div class="popup" id="popup">
            <div class="popTitle" id="popTitle">
                <span class="title_left">提示</span> <span class="title_right">×</span> 
            </div> 
            <p class="popup_text" id="popup_text">你好</p>
            <input type="submit" class="popup_buttom" onclick="closePopup()" value="确 定"/>
        </div>
</body>
</html>

 

 

ps:有人可以指点下移动提示框怎么做吗?

  • 写回答

1条回答 默认 最新

  • 上官熊猫 2020-12-28 09:19
    关注

    querySelector的参数为css选择器,而不是class名,应为document.querySelector(".popTitle");如果没有在内联设置left值,可以通过window.getComputedStyle(document.querySelector('.box'),null)['left']获取,此方法可获取所有的css属性及值

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 4月7日
  • 已采纳回答 3月30日

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line