我正在使用 Drupal 7 开发一个带有表单 API 的自定义表单和一个带有复选框的 tableselect。对于要使用 jquery 编码的复选框的选择,我有一些限制。我为 onclick 复选框创建了一个函数,在 drupal 之外它的工作原理就像你可以在这里看到的那样,但是当我尝试与 drupal 集成时,jquery 选择器根本不起作用。
所以这是我在drupal中的代码:
$form ['#attached'] ['js'] = array (drupal_get_path ( 'module',
'form_cuentacorriente' ) . '/checkboxes.js' );
$form ['tabla'] = array (
'#type' => 'tableselect',
'#header' => $tabla ['header'],
'#options' => $tabla ['body'],
'#attributes' => array ('id' => 'conceptos')
);
这是我的js函数:
(function($){
$('input[type=checkbox]').click(function(){
var tabla = $("#conceptos")[0];
var long = tabla.rows.length;
var pos = $(this).closest("tr").index();
if (!this.checked){
for (i = pos+1; i < long +1; i++) {
$(tabla.rows[i]).find( 'input' ).prop('disabled', !this.checked).prop('checked', false);
}
}else{
$(this).closest("tr").next().find("input")
.prop('disabled', !this.checked);
}
});
})(jQuery);
如果我使用 * 选择器,它在我点击的任何地方都可以工作,但 'input[type=checkbox]' 不起作用。Drupal 7 上的 JQuery 1.10 版本
任何想法我错过了什么?
提前致谢!