我有这个javascript函数和html代码,我想在每种情况下设置$ _SESSION [' gen']不同。但是,点击它并不重要,它总是返回最后一个,摇滚。但是,警报顺利,并返回正确的ID。
window.onload = function() {
$("a.a").click(function() {
// alert(this.id);
//return false;
switch(this.id)
{
case 1:
{<?php $_SESSION['gen']='Alternative'; ?>}
break;
case 2:
{<?php $_SESSION['gen']='Blues'; ?>}
break;
case 3:
{ <?php $_SESSION['gen']='Classical'; ?>}
break;
case 4:
{<?php $_SESSION['gen']='Reggae'; ?>}
break;
case 5:
{<?php $_SESSION['gen']='Electronic'; ?>}
break;
case 6:
{<?php $_SESSION['gen']='Country'; ?>}
break;
case 7:
{<?php $_SESSION['gen']='Folk'; ?>}
break;
case 8:
{ <?php $_SESSION['gen']='Hip Hop'; ?>}
break;
case 9:
{<?php $_SESSION['gen']='Pop'; ?>}
break;
case 10:
{<?php $_SESSION['gen']='Rock'; ?>}
break;
}
});
}
<dl id="browse">
<dt>Full Category Lists</dt>
<dd class="first"><a href="genre.php" name="a" id="1" class="a">Alternative</a></dd>
<dd><a href="genre.php" name="a" id="2" class="a">Blues</a></dd>
<dd><a href="genre.php" name="a" id="3" class="a">Classical</a></dd>
<dd><a href="genre.php" name="a" id="4" class="a">Reggae</a></dd>
<dd><a href="genre.php" name="a" id="5" class="a">Electronic</a></dd>
<dd><a href="genre.php" name="a" id="6" class="a">Country</a></dd>
<dd><a href="genre.php" name="a" id="7" class="a">Folk</a></dd>
<dd><a href="genre.php" name="a" id="8" class="a">Hip Hop</a></dd>
<dd><a href="genre.php" name="a" id="9" class="a">Pop</a></dd>
<dd class="last"><a href="genre.php" name="a" id="10" class="a">Rock</a></dd>
</dl>