Using #attached to attach js to form by a custom module
@NoSssweat is it possible only load for add/edit node and webform(not
  search form)? – CocoSkin


You can by utilizing hook_form_BASE_FORM_ID_alter

For node's add/edit form:

/**
 *  Implements hook_form_BASE_FORM_ID_alter.
 */
function mymodule_form_node_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  $form['#attached']['js'][] = drupal_get_path('module', 'mymodule') . '/js/custom.js';
}


For Webform:

/**
 *  Implements hook_form_BASE_FORM_ID_alter.
 */
function mymodule_form_webform_client_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  $form['#attached']['js'][] = drupal_get_path('module', 'mymodule') . '/js/custom.js';
}