简明现代魔法 -> JavaScript -> Javascript 带参选择跳转
2009-11-10
随机数字为 2
跳转测试
var thisdoc=document.gallery; 这句代码中,gallery 其实是隐含表单的名字,这个 javascript 其实也是利用表单实现跳转。
在 a 标签里加上 onclick='jsEditAlbum(<?=$album?>,将参数传递给 javascript 进行选择跳转。
$album 是数组 album_id 随机产生的。
<script type="text/javascript"> function jsEditAlbum(bid){ var thisdoc=document.gallery; if (bid == 1){ thisdoc.action='hello.php'; thisdoc.a_id.value=bid; thisdoc.submit(); } else if (bid == 2){ thisdoc.action='error.php'; thisdoc.a_id.value=bid; thisdoc.submit(); } else if (bid == 3){ thisdoc.action='error3.php'; thisdoc.a_id.value=bid; thisdoc.submit(); } else if (bid == 4){ thisdoc.action='error4.php'; thisdoc.a_id.value=bid; thisdoc.submit(); } } </script> <?php $album_id = array('1','2','3','4'); $rand = array_rand($album_id, 1); $album = $album_id[$rand]; echo $album; ?> <form name='gallery' action='gallery.php' method='post'> <input type=hidden name='curpage'> <input type=hidden name='saction'> <input type=hidden name='b_id'> <input type=hidden name='a_id'> <input type=hidden name='saction'> <input type=hidden name='stext'> <input type=hidden name='stype'> <a href="#" onclick='jsEditAlbum(<?=$album?>)' >跳转测试</a>
注:如需转载本文,请注明出处(原文链接),谢谢。更多精彩内容,请进入简明现代魔法首页。
copyright © 2009 简明现代魔法 学习、分享、进步
power by Gonn 感谢所有关心和支持本站的朋友们