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

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 01:19
    关注

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

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

报告相同问题?

问题事件

  • 系统已结题 4月6日
  • 已采纳回答 3月30日
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部