ورود

View Full Version : مشکل عدم تغییر مکان شی



asgarkz
یک شنبه 03 اسفند 1393, 00:19 صبح
با سلام
یک شی (مثلا یک textbox ) را که از طریق کد html ایجاد شده است درنظر بگیرید. من میخوام خصوصیت left این شی رو از طریق کد جاوااسکریپت تغییر بدم ولی نمیتونم. جالب اینجاست که خصوصیات width و height رو میتونم تغییر بدم
کد نمونه به شرح زیر است:




<body>

<input type='text' id='t1'>

<script type='text/javascript'>
var xobj;
xobj = document.getElementById('t1');
xobj.style.width = 322;
xobj.style.height = 152;
xobj.style.left = 200;
</script>

</body>

Moien Tajik
یک شنبه 03 اسفند 1393, 19:20 عصر
<body>

<input type='text' id='t1'>

<script type='text/javascript'>
var xobj;
xobj = document.getElementById('t1');
xobj.style.width = 322;
xobj.style.height = 152;
xobj.style.position = 'absolute';
xobj.style.left = 200;
</script>

</body>

asgarkz
سه شنبه 05 اسفند 1393, 22:51 عصر
با تشکر
الان میخوام مکان button رو با توجه مکان Text تغییر داده و در فاصله 50 پیکسلی از اون قرارش بدم. با توجه به کد زیر باید خاصیت left در button تغییر بکنه که انجام نمیشه. لطفا راهنمایی کنید


<head>
<style>
.TextClass
{
position: absolute;
height: 70px;
width: 100px;
left: 20px;
top: 20px;
}
.ButtonClass
{
position: absolute;
height: 70px;
width: 120px;
top: 100px;
}
</style>
</head>
<body>
<input type='text' class='TextClass' id='xText' value='Text'>
<input type='button' class='ButtonClass' id='xButton' value='Button'>
<script type='text/javascript'>
var zText, zButton;
zText = document.getElementById('xText');
zButton = document.getElementById('xButton');
zButton.style.left = zText.style.left + zText.style.width + 50;
</script>
</body>