Drupal - 向所有提交按钮添加类

发布于 2024-12-22 14:17:08 字数 129 浏览 2 评论 0原文

我的网页中有几个表单,我希望能够向所有提交按钮添加一个类(现在我有表单提交作为标准)。而且,在某些表单中,我有使用 AHAH 来显示某些内容的按钮,但我不希望这些按钮具有新类,而只希望那些在表单上进行最终提交的按钮。

提前致谢!

I have several forms in my webpage, and I want to be able to add a class to all my submit buttons (right now I have form-submit as standard). And also, in some forms I have button which uses AHAH in order to show something, but I don't want these to have the new class, only those button who does the final submit on the form.

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

岁吢 2024-12-29 14:17:08

或者您可以覆盖负责提交按钮的theme_button。将其放入 template.php 文件中,并确保在进行更改后清除缓存。您可以 var_dump $element 并查看如何区分提交按钮。

/**
 * Overwrite theme_button()
 * @file template.php
 * !replace my_theme with the name of your active theme
 */
function my_theme_button($element) {

  // Add some extra conditions to make sure we're only adding
  // the classto the right submit button
  if ($element['#id'] == 'edit-submit') {
    // Now add our custom class
    if (isset($element['#attributes']['class'])) {
      $element['#attributes']['class'] .= ' extra-class';
    }
    else {
      $element['#attributes']['class'] = 'extra-class';
    }
  }

  return theme_button($element);
}

Or you can overwrite theme_button which is responsible for the submit buttons. Place this in the template.php file and make sure to clear the cache after you make the changes. You can var_dump the $element and see how you can differentiate between the submit buttons.

/**
 * Overwrite theme_button()
 * @file template.php
 * !replace my_theme with the name of your active theme
 */
function my_theme_button($element) {

  // Add some extra conditions to make sure we're only adding
  // the classto the right submit button
  if ($element['#id'] == 'edit-submit') {
    // Now add our custom class
    if (isset($element['#attributes']['class'])) {
      $element['#attributes']['class'] .= ' extra-class';
    }
    else {
      $element['#attributes']['class'] = 'extra-class';
    }
  }

  return theme_button($element);
}
三人与歌 2024-12-29 14:17:08

或者使用 jQuery:

jQuery("form .form-submit:last-child").addClass("your-custom-class");

Or use jQuery:

jQuery("form .form-submit:last-child").addClass("your-custom-class");
梦旅人picnic 2024-12-29 14:17:08

您不需要其他类,只需做出正确的 CSS 选择:

form .form-submit:last-child { color: red; }

这将仅设置页面上每个表单上最后一个提交按钮的样式。

you don't need other classes, just make the right CSS selection:

form .form-submit:last-child { color: red; }

this will style only the last submit button on every form on your page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文