我有这个:
$('li').click(function() {
var currentSrc = $('img', this).attr('src').toString();
var grabAlt = $('img', this).attr('alt').split('|');
//alert(grabAlt[0]);
$('.imgSample img').attr('src', currentSrc);
$('.projectDescription').html('<p class="projectDescription">' + grabAlt[0].join('</p>'));
$('.projectTitle').html(grabAlt[1]);
});
当我删除 [0] 和 [1] 时,我可以提醒任何一个,我认为是第一个值 [0],确实替换了项目描述,但是尝试将每个值放在各自的位置根本不起作用.
相关html片段:
<section class="workArea">
<div class="imgSample"><img src="images/samples/testImage2.png" alt="This first part will be a short description. | this second part will be the title."></div>
<p class="projectDescription">This is to be replaced when an image is clicked on.</p>
<h3 class="projectTitle">To be replaced</h3>
</section>
</div>
<nav>
<ul class="print">
<li class="liRounded"><img width="50" height="50" src="images/samples/image1.png" alt="Should replace the content in the paragraph. | Replace title copy."></li>
<li class="liRounded"><img width="50" height="50" src="images/samples/image2.png" alt="Second. | Replace title 2."></li>
<li class="liRounded"><img width="50" height="50" src="images/samples/image3.png" alt="third. | Replace title 3."></li>
</ul>
</nav>
是我的语法或用法在这里错误吗?