You cannot invoke JavaScript functions in standard HTML attributes other than onXXX
.(您不能在onXXX
以外的标准HTML属性中调用JavaScript函数。)
Just assign it during window onload.(只需在窗口加载期间分配它。)
<script type="text/javascript">
window.onload = function() {
document.myform.action = get_action();
}
function get_action() {
return form_action;
}
</script>
<form name="myform">
...
</form>
You see that I've given the form a name
, so that it's easily accessible in document
.(您看到我已经为表单指定了name
,因此可以在document
轻松访问。)
Alternatively, you can also do it during submit
event:(或者,您也可以在submit
活动期间执行此操作:)
<script type="text/javascript">
function get_action(form) {
form.action = form_action;
}
</script>
<form onsubmit="get_action(this);">
...
</form>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…