因为点击链接时还需要传递隐形参数,所以调用javascript来处理
//a.php:
.....
echo "<a href='' onclick=\"nextPage('$name','$mask')\">$name</a>";
//javascript:function nextPage(cName,maskAddr)
{
document.open();
document.write("<form action='b.php?name="+cName+"' name='form1' method='post'>");
document.write("<input type='hidden' name='mAddr' value='"+maskAddr+"'>");
document.write("</form>");
document.form1.submit();
document.close();
}这段代码在ie下是可以运行的,但是在mozilla 的seamonkey下没有任何反应。请问哪里有错吗?mozilla是在系统linux下运行的。是这个浏览器不认吗?我之前用document.其它参数都挺好用的阿。
//a.php:
.....
echo "<a href='' onclick=\"nextPage('$name','$mask')\">$name</a>";
//javascript:function nextPage(cName,maskAddr)
{
document.open();
document.write("<form action='b.php?name="+cName+"' name='form1' method='post'>");
document.write("<input type='hidden' name='mAddr' value='"+maskAddr+"'>");
document.write("</form>");
document.form1.submit();
document.close();
}这段代码在ie下是可以运行的,但是在mozilla 的seamonkey下没有任何反应。请问哪里有错吗?mozilla是在系统linux下运行的。是这个浏览器不认吗?我之前用document.其它参数都挺好用的阿。
我单独运行document.write("hello")也不行,但是把这个语句加在上面那段代码里,就能显示hello,但是立刻它就跳回到a.php页面,没有转到b.php去。应该不是浏览器不认document.write()这个函数,难道是不认后面的html代码?
但有些基本的问题还是不要忽略。
1.firefox不能用document.form1这种形式,应该给form加上个id,使用document.getElementById获取dom
2.firefox对于<a>标签,首先执行href外部链接,再执行onclick,至少ff3.0是这样的,你href='',实际上是链接到了本页面,可以考虑javascript:伪协议
3.document.write html标签,有两个步骤,一是浏览器write,二是dom的加载,你write完form就尝试获取form节点,至少firefox有这方面的问题,有可能因为dom未load完而找不到节点。
兼容问题就像雷区,不小心就踩进去了。。
参考:
=========
<html>
<body>
<?php $name='abc';$mask='efg';echo " <a href=\"javascript:nextPage('$name','$mask')\">$name </a>"; ?>
<script>
function nextPage(cName,maskAddr)
{
document.open();
document.write(" <form action='b.php?name="+cName+"' name='form1' id='form1' method='post'>");
document.write(" <input type='hidden' name='mAddr' value='"+maskAddr+"'>");
document.write(" </form>");
document.write("<"+"script type='text/javascript'>setTimeout(function(){document.getElementById('form1').submit()},100);</"+"script>");//延迟一下再提交
document.close();
}
</script>
</body>
</html>
先谢谢。
我试了,还是不行,加上timeout那个,连ie也不显示了。我直接用document.getElementById('form1').submit(),ie没问题,但mozilla家的还是不行,显示document.getElementById('form1')的值是null
你的ie提示是什么错误?
直接用document.getElementById('form1').submit,在ff下有可能就会出现dom未找到的情况。
哦,不好意思,有个字母写成大写,改过来后,ie是好的。但是ff还是不行。我的ff也是3.0,一直一片空白,没有转到新的页面,还一直在load,就死在那
当然有用拉,这就是我现在在写的东西。要完成的功能主贴里已经说啦,a href链接传递隐形参数,我不可能把所有参数都写到地址的?后面。当然用button更好实现,但一网页的button多难看。
document is not defineddocument.getElementById("form1") is null
找不到form的名字。IE得到是[objet]