2011-12-22 22 views
2

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

在此先感谢!

回答

8

或者你可以覆盖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); 
} 
0

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

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

这将样式只有最后提交网页上的每个窗体上按钮。

+0

最后一个孩子在所有浏览器中都不支持,因此我需要向所有提交按钮添加一个类。 – Carnal

+0

它在IE 8及更低版本中不受支持。所有其他浏览器都可以。即使IE 9和新的IE 10 –

+0

好吧,但我试过你的方法,它没有工作,你不知道如何实现我第一次建议!? – Carnal

1

或者使用jQuery:

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