PDA

View Full Version : عدم تغییر خاصیت left



asgarkz
چهارشنبه 06 اسفند 1393, 20:59 عصر
با سلام خدمت دوستان
با توجه به کد زیر باید خاصیت 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>

asgarkz
پنج شنبه 07 اسفند 1393, 21:01 عصر
ظاهرا توی پست قبلی، مشکل رو درست مطرح نکردم. در واقع مشکل اینه که با جاوااسکریپت نمیتونم از خاصیت left یا width یک شی مثل button استفاده کنم.
در نمونه کد زیر مقدار left با دستور alert مشاهده نمیشود. به صورت window.alert(zButton.style.left هم جواب نمیده. لطفا راهنمایی کنید.


<head>
<style>
.bClass
{
position: absolute;
left: 50;
width: 100;
}
</style>
</head>
<body>
<input type='button' class='bClass' id='xButton' value='Test'>
<script type='text/javascript'>
var zButton;
zButton = document.getElementById('xButton');
window.alert(zButton.left);
</script>
</body>

Moien Tajik
جمعه 08 اسفند 1393, 14:02 عصر
ابن رو امتحان کنین :
window.alert(zButton.style.position.left)

asgarkz
جمعه 08 اسفند 1393, 20:30 عصر
نه جواب نداد. پیغام undefined میده.

asgarkz
شنبه 09 اسفند 1393, 00:07 صبح
ظاهرا وقتی کد zButton.style.left='500' رو قبل از alert اضافه میکنم، تابع alert درست عمل میکنه. ولی من میخوام بدون این انتساب، تابع alert مقدار left رو نشون بده


<head>
<style>
.bClass
{
position: absolute;
left: 50;
width: 100;
}
</style>
</head>
<body>
<input type='button' class='bClass' id='xButton' value='Test'>
<script type='text/javascript'>
var zButton;
zButton = document.getElementById('xButton');
zButton.style.left='500';
window.alert(zButton.style.left);
</script>
</body>

asgarkz
شنبه 09 اسفند 1393, 22:50 عصر
با تشکر از همه دوستان، با کد زیر مشکل حل شد


<head>
<style>
.bClass
{
position: absolute;
left: 50;
width: 100;
}
</style>
</head>
<body>
<input type='button' class='bClass' id='xButton' value='Test'>
<script type='text/javascript'>
var zButton;
zButton = document.getElementById('xButton');
zButton = zButton.getBoundingClientRect();
window.alert(zButton.left);
</script>
</body>