【问题标题】:Append is not working in Drupal附加在 Drupal 中不起作用
【发布时间】:2014-08-13 10:41:05
【问题描述】:

我想在 drupal 中的表格后添加两个按钮。我使用表 id 和追加,但它不工作。我不知道是什么问题,控制台中没有显示错误。

这里是代码。请帮忙

(function($){
  $('#edit-submitted-new-table-element').appendTo('<a href="javascript:void(0);" class="addmorebtn form-submit">Add More</a> <a href="javascript:void(0);" class="hidebtn form-submit">Hide it</a>');
$('.hidebtn').css('display', 'none');
alert('h1');
var numcount = 0;
$('#edit-submitted-new-table-element .addmorebtn').live('click', function(){
numcount++;
if(numcount >0 && numcount < 2){
    $('#edit-submitted-new-table-element tr:nth-last-child(2)').css('display', ' table-row');
}
else if(numcount >1 && numcount < 3){
    $('#edit-submitted-new-table-element tr:last-child()').css('display', ' table-row');
    $('.addmorebtn').css('display', 'none');
    $('.hidebtn').removeAttr('style');
    $('.hidebtn').css('display', 'inlne-block');
}

});
$('#edit-submitted-new-table-element .hidebtn').live('click', function(){

if(numcount >= 2 && numcount < 3){
    $('#edit-submitted-new-table-element tr:last-child().odd').removeAttr('style');
}
else if(numcount >=1 && numcount < 2){
    $('#edit-submitted-new-table-element tr:nth-last-child(2).even').removeAttr('style');
    $('.hidebtn').css('display', 'none');
    $('.addmorebtn').removeAttr('style');
     $('.addmorebtn').css('display', 'inline-block');
}
numcount--;
});

}(jQuery));

I want to add two button after table in drupal. I use table id and append but it is not working...
I don't know what is the problem and no error is showing in console.
Here is code . Please help

【问题讨论】:

  • 尝试将$('#edit-submitted-new-table-element').appendTo(改为$('#edit-submitted-new-table-element').append(

标签: jquery drupal-7


【解决方案1】:

您使用appendTo,而不是append 来介绍您的代码。改变它:

$('#edit-submitted-new-table-element').append(...)

您还必须更改正在使用的选择器。例如last-child() 不正确。为此更改它:

$('#edit-submitted-new-table-element tr:last-child')...
$('#edit-submitted-new-table-element tr.odd:last-child').removeAttr('style');
$('#edit-submitted-new-table-element tr.even:nth-last-child').removeAttr('style');

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 2016-02-26
    • 2014-10-05
    • 2017-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-11
    相关资源
    最近更新 更多