<a href="javascript:SelectAll(this.form)">All </a>
<input type ="button" value ="test" onClick="SelectAll(this.form);" />
<script ......>
function SelectAll(form)
{
alert(form);
}
</script>
方法 1 产生一条警报消息“未定义”,而方法 2 通过显示表单对象可以正常工作。我非常清楚 anchor 元素没有 form
属性,它引用 form ,与输入元素不同,但是有没有其他方法可以使用超链接传递表单对象,或者有什么方法将按钮设置为看起来像超链接
谢谢
最佳答案
试试这个...
onClick="SelectAll(getParentForm(this));"
function getParentForm(el) {
while(el = el.parentNode) {
if(el.tagName.toLowerCase() === "form")
return el;
}
return null;
}
关于javascript - 从超链接将表单对象传递给 javascript 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1137870/