我有3个字段集合,第一个是父字段,另有2个字段集合是子字段集合。
将字段设置为“无限”到父字段集合(即学生信息)。
现在我要隐藏2个子字段集合(即英语信息和数学信息),点击“添加另一项”,我已经使用jquery隐藏了子字段FC。
特别代表:
jQuery('.child1').hide();
jQuery('.child2').hide();
子字段集合最初隐藏,但如果我单击“添加另一项”按钮,则jquery将被删除并显示子FC。我尝试过在jquery中绑定click事件,但它不起作用。
发布于 2018-09-06 23:14:10
您能否将JS文件中的代码替换为以下代码:
(function ($, Drupal, drupalSettings) {
'use strict';
Drupal.behaviors.myModuleName = {
attach: function (context, settings) {
$('#node-student-form .field--type-field-collection .field--name-field-child-english-info').css("display","none"); // Child FC 1
$('#node-student-form .field--type-field-collection .field--name-field-child-maths-info').css("display","none"); // Child FC 2
}
};
})(jQuery, Drupal, drupalSettings);
这是基于这个文章的,attach()
函数确保每次进行Ajax调用时代码都运行。
https://drupal.stackexchange.com/questions/268877
复制相似问题