html元素的位置不起作用? [英] Positioning of html elements is not working ?

查看:92
本文介绍了html元素的位置不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在尝试使用jquery在另一个按钮下放置一个按钮,但它仍停留在它的位置.知道在警告其顶部和左侧时,它们会为我提供我想要的正确值.那么如何解决呢?

这是代码:

Hi all ,

I am trying to place a button under another button using jquery but it is staying in its place.Knowing that when alerting its top and left they are giving me correct values as i want.So how to fix it ?

Here is the code :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Untitled Page</title>

    <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>

</head>
<body>
    <form action="">
    <input type="button" id="placeit" value="placeit" name="btn2" />
    <input id="btn1" type="button" name="btn1" value="button" />
    <p>
    </p>
    </form>

    <script type="text/javascript">
        var p = $("#btn1");
        var position = p.position();
        var place = document.getElementById("placeit");
        place.top = position.top + 30;
        place.left = position.left;
        alert(place.top);
        alert(place.left);
        $("p:last").text("left: " + position.left + ", top: " + position.top);
    </script>

</body>
</html>

推荐答案

(#btn1"); var position = p.position(); var place = document.getElementById("placeit"); place.top = position.top + 30; place.left = position.left; alert(place.top); alert(place.left);
("#btn1"); var position = p.position(); var place = document.getElementById("placeit"); place.top = position.top + 30; place.left = position.left; alert(place.top); alert(place.left);


("p:last").text("left:" + position.left +,top:" + position.top); < /script > < /body > < /html >
("p:last").text("left: " + position.left + ", top: " + position.top); </script> </body> </html>


看看这个:
http://manifestwebdesign.com/developer-resources/setting-offset-with-jquery/ [ ^ ]

仔细阅读脚本,您将看到需要做的事情. (提示: css位置 [
Take a look at this:
http://manifestwebdesign.com/developer-resources/setting-offset-with-jquery/[^]

Read the script carefully, and you''ll see what you need to do. (hint: css position[^])

Best regards
Espen Harlinn


这篇关于html元素的位置不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆