我想在我的 drupal 站点上的所有表单的提交按钮中添加一个 onmouseover 事件。
我怎样才能做到这一点?
本
我想在我的 drupal 站点上的所有表单的提交按钮中添加一个 onmouseover 事件。
我怎样才能做到这一点?
本
通过将以下代码添加到自定义模块,我设法部分解决了我的问题:
function defprofile_form_alter(&$form, &$form_state, $form_id) {
$form['submit']['#attributes'] = array('onMouseOver' => "this.style.backgroundColor='#cc0000'",'onMouseOut' => "this.style.backgroundColor='#000'"); }
但是,这只适用于提交按钮,我希望它适用于所有按钮。我尝试用“按钮”替换“提交”,但代码完全停止工作。
使用 jQuery:
$(document).ready(function(){
$('input[type="submit"]').hover(
function(){
// Do something with $(this)
}
);
});
编辑:更新了另一种可能的解决方案,因为您只需要更新背景颜色。
如果您不关心 IE6 支持,您也可以:hover
为您的提交按钮使用 CSS 伪选择器,并且不需要任何 javascript。确保所有提交按钮都设置了一个类(我'submit'
在本例中用作类名)。
.submit {
background-color: #ddd;
}
.submit:hover {
background-color: #f00;
}