drupal6-在表单提交时运行JavaScript代码

drupal 6 - Run JavaScript code on form submission

本文关键字:JavaScript 代码 运行 表单提交 drupal6-      更新时间:2023-09-26

我想在表单提交时执行其他默认任务之前,在提交的表单上运行JavaScript代码。

有人能提出一些方法吗?

例如,以下是如何在使用jQuery:提交Drupal的联系人表单之前在其上执行一些JS

$('form#contact-mail-page input#edit-submit').click(function() { alert('do some stuff'); });

我不确定drupal是否有任何特殊的方法来自动化或使其更容易,但在普通的HTML javascript中,你会这样做:

<input type="submit" onClick="doStuff();" value="Submit">  //Note: you can use return(doStuff()); and if doStuff returns false then the form will not submit (great for checking if all fields are filled out correctly).

您可以使用的此属性

'#attributes' => array('onclick' => 'if(confirm('.$msg.')) return true; return false;'));