Javascript 按id提交表单的函数
如何使用表单id作为函数参数提交表单?会不会是这样的: HTML:Javascript 按id提交表单的函数,javascript,forms,Javascript,Forms,如何使用表单id作为函数参数提交表单?会不会是这样的: HTML: <a href="#" onclick="confirmSubmit(form1)">Delete file</a> function confirmSubmit(id) { var agree=confirm("Are you sure you wish to delete this file?"); if (agree) document.getElementById
<a href="#" onclick="confirmSubmit(form1)">Delete file</a>
function confirmSubmit(id) {
var agree=confirm("Are you sure you wish to delete this file?");
if (agree)
document.getElementById('form' + id).submit();
else
return false;
}
定义要形成的id(如果要按id引用)
功能确认提交(id){
var agree=confirm(“您确定要删除此文件吗?”);
如果(同意)
document.getElementById(id.submit();
其他的
返回false;
}
您可以将表单id作为字符串参数(用单引号表示)传递给onClick函数
见下文
<a href="#" onclick="confirmSubmit('form1')">Delete file</a>
function confirmSubmit(id) {
var agree=confirm("Are you sure you wish to delete this file?");
if (agree)
document.getElementById(id).submit();
else
return false;
}
功能确认提交(id){
var agree=confirm(“您确定要删除此文件吗?”);
如果(同意)
document.getElementById(id.submit();
其他的
返回false;
}
是这样的吗,你还没有试过吗?@Andreas,是的,我试过,但1)它不起作用2)我想知道是否有更简单的方法1)应该是问题的一部分,包括错误消息2)是1)解析后的第二步,因为如果在onclick
属性中用引号括起参数,代码应该可以工作
<a href="#" onclick="confirmSubmit('form1')">Delete file</a>
function confirmSubmit(id) {
var agree=confirm("Are you sure you wish to delete this file?");
if (agree)
document.getElementById(id).submit();
else
return false;
}