急!急!急!简单高分的问题!!!!!(在线等待!) 你例子中的form不是有名字吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <script>function f(obj){ alert(obj.parentElement.name);}</script><form name="f1"><a href="#" onClick="f(this)">1</a></form><form name="f2"><a href="#" onClick="f(this)">2</a></form><form name="f3"><a href="#" onClick="f(this)">3</a></form> <script>function f(obj){ var theForms=document.forms; if(theForms==null) return null; for(var i=0;i<theForms.length;i++) { if(theForms[i].contains(obj)) return theForms[i]; } return null;}</script><form name="f1"><a href="#" onClick="alert(f(this).name);">1</a></form> <form name="f2"><a href="#" onClick="alert(f(this).name);">2</a></form> <form name="f3"><a href="#" onClick="alert(f(this).name);">3</a></form> <form name="f4"><a href="#" onClick="alert(f(this).name);">4</a></form> 很简单,你在onClick方法中传入this,然后在f函数中添加这个代码:function f(obj){ while (obj.parentElement.tagName != "FORM") { obj = obj.parentElement; } obj = obj.parentElement; alert(obj.name);}Good Luck! 下面那样就OK,测试通过!<script>function f(obj){ alert(obj.name);}</script><form name="f1"><a href="#" onClick="f(f1)">1</a></form><form name="f2"><a href="#" onClick="f(f2)">2</a></form><form name="f3"><a href="#" onClick="f(f3)">3</a></form> 对于以下四种对象,可以引用form属性.BUTTON, INPUT, SELECT, TEXTAREA 例如<form name="f1"><button onClick="alert(form.name);">Button</button></form> 而A对象,则不可以引用form属性,故楼主的代码会报错 to:各位大侠,能在netscape下面运行吗? 我给你的那段在IE中测试通过。netscape中能不能用你自己试试 不能运行,netscape4.76下面theForms[i].contains和obj.parentElement不能识别,还有没有其他办法呢? form没有名字,例子中不是有吗? to:xzq686(瞬)那是我为了确认是访问的哪一个form而写的,实际上是没有名字的. <script>function f(obj){ alert(document.forms[obj].name);}</script><form name="f1"><a href="#" onClick="f(0)">1</a></form><form name="f2"><a href="#" onClick="f(1)">2</a></form><form name="f3"><a href="#" onClick="f(2)">3</a></form> Extjs 读取store数据问题 求一段js匹配正则,取得value的值 javascript遍历文件夹名称,出现问题,VBS同样操作无问题,求解 请教:全选 和 反选 checkbox ie8下JS无法预览图片 javascript 控制display 问题 求一个简单工具栏,帮忙看看代码 document.createElement后看不到结果 请问Red Hat Linux下要用Javascript怎么配置呀!谢谢,在线等 请问大家学习js得书什么最好 弹出窗口刷新它的父页面 checkbox的疑惑
function f(obj){
alert(obj.parentElement.name);
}
</script>
<form name="f1">
<a href="#" onClick="f(this)">1</a>
</form>
<form name="f2">
<a href="#" onClick="f(this)">2</a>
</form>
<form name="f3">
<a href="#" onClick="f(this)">3</a>
</form>
function f(obj){
var theForms=document.forms;
if(theForms==null) return null;
for(var i=0;i<theForms.length;i++)
{
if(theForms[i].contains(obj))
return theForms[i];
}
return null;
}
</script>
<form name="f1">
<a href="#" onClick="alert(f(this).name);">1</a>
</form>
<form name="f2">
<a href="#" onClick="alert(f(this).name);">2</a>
</form>
<form name="f3">
<a href="#" onClick="alert(f(this).name);">3</a>
</form>
<form name="f4">
<a href="#" onClick="alert(f(this).name);">4</a>
</form>
然后在f函数中添加这个代码:
function f(obj)
{
while (obj.parentElement.tagName != "FORM")
{
obj = obj.parentElement;
}
obj = obj.parentElement;
alert(obj.name);
}Good Luck!
<script>
function f(obj){
alert(obj.name);
}
</script>
<form name="f1">
<a href="#" onClick="f(f1)">1</a>
</form>
<form name="f2">
<a href="#" onClick="f(f2)">2</a>
</form>
<form name="f3">
<a href="#" onClick="f(f3)">3</a>
</form>
例如
<form name="f1">
<button onClick="alert(form.name);">Button</button>
</form> 而A对象,则不可以引用form属性,故楼主的代码会报错
那是我为了确认是访问的哪一个form而写的,实际上是没有名字的.
function f(obj){
alert(document.forms[obj].name);
}
</script>
<form name="f1">
<a href="#" onClick="f(0)">1</a>
</form>
<form name="f2">
<a href="#" onClick="f(1)">2</a>
</form>
<form name="f3">
<a href="#" onClick="f(2)">3</a>
</form>