2011-12-22 19 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

last-childはすべてのブラウザでサポートされていないため、すべての送信ボタンにクラスを追加する必要があります。 – Carnal

+0

IE 8以降ではサポートされていません。他のブラウザはすべてOKです。 IE 9と新しいIE 10でも –

+0

申し訳ありませんが、私はあなたの方法を試してみました。それは仕事をしませんでした。 – Carnal

1

または使用のjQuery:

jQuery("form .form-submit:last-child").addClass("your-custom-class"); 
関連する問題