Calling Multiple functions simultaneously
I'm trying to call two different functions for two d开发者_如何学JAVAifferent HTML elements at the same time, but the second function isn't being read at all. I'm also trying to use the id to specify which corresponding elements to grab data from. Here's what I have:
function changeImage(id)
{
var s = document.getElementById('showcase');
var simg = s.getElementsByTagName('img');
var slen = simg.length;
for(i=0; i < slen; i++)
{
simg[i].style.display = 'none';
}
$('#' + id).fadeIn('slow', 0);
function createComment(jim)
{
//alert('hello?');
var d = document.getElementById('description');
var dh = document.getElementsByTagName('p');
var dlen = dh.length;
//alert(dh);
for(i=0; i < dlen; i++)
{
alert(dh);
dh[i].style.display = 'none';
}
$('#' + jim).fadeIn('slow', 0);
}
It appears you are missing the closing bracket}
at the end of your changeImage function.
Also you could shorten your script substantially using jQuery:
function changeImage(id)
{
$('#showcase img').hide();
$('#' + id).fadeIn('slow');
}
function createComment(jim)
{
$('#description p').hide();
$('#' + jim).fadeIn('slow');
}
Also, I'm not sure why you have a zero inside the fadeIn()
function? If you want the img/p to show instantly, just use .show()
精彩评论