ورود

View Full Version : سلام



olampiad
جمعه 26 مهر 1392, 00:58 صبح
سلام
مشکل این کد چیه؟



document.getElementById('jj').onclick=function(){
document.getElementsByClassName('hidden-text').style.display=block;
}



من می خوام موقعی که روی لینک کلیک شد دایومان نمایش داده شود.
ولی کار نمی کند.

اینم کد html


<a id="jj" href="">click</a>
<div class="hidden-text" id="ff" >
<p>More than 50,000 school students travelled from across the province to attend the event to see first-hand what career options are available in the skills, trades and technology sectors. They also test-drove various skills at the Try-A-Skill tent.</p>
<p>More than 55 Calgary schools participated in the One School One Country program, where elementary schools adopted a team and learned about the culture of their country prior to meeting their team’s Competitors at their school prior to competition.</p>
</div>

2undercover
جمعه 26 مهر 1392, 06:19 صبح
شما فقط توی jQuery می تونید روی چندین عنصر هم زمان کار کنید!

الان متد getElementsByClassName یک آرایه رو بر می گردونه پس یا باید با حلقه ی for تک تک اون عمل رو روشون اجرا کنید یا هم که اگر فقط به یک عنصر اشاره دارید روی عنصر اول آرایه اون عمل رو اجرا کنید یعنی اینجوری:
document.getElementsByClassName('hidden-text')[0].style.display='block';

البته یک مشکل دیگه هم اینکه باید block رو توی " یا ' قرار بدید و گرنه به عنوان متغیر شناخته میشه!

tmwebseo
شنبه 27 مهر 1392, 10:12 صبح
[QUOTE=olampiad;1898482]سلام
مشکل این کد چیه؟



document.getElementById('jj').onclick=function(){
document.getElementsByClassName('hidden-text').style.display=block;
}




سلام
شما باید یا javascript بنویسید یا jquery

function test(){
document.getElementsByClassName('hidden-text').style.display=block;
}


<input onclick="return test()">