简体   繁体   English

jQuery - 在引导模式中隐藏一个元素

[英]jQuery - hide an element inside bootstrap modal

I am trying to hide a button (assume this as buttonA) inside a bootstrap modal popup.我试图在引导模式弹出窗口中隐藏一个按钮(假设它为 buttonA)。 Here I have buttonB and buttonC at different places and both are used to trigger the same popup but my problem is I have to hide buttonA when popup is triggered from buttonB and show it when triggered from buttonC.在这里,我在不同的地方有 buttonB 和 buttonC,它们都用于触发相同的弹出窗口,但我的问题是当从 buttonB 触发弹出窗口时我必须隐藏 buttonA,并在从 buttonC 触发时显示它。

I tried the below generic code in jQuery but it is not working for me, is there any way to make this happen while using bootstrap modal popup.我在 jQuery 中尝试了下面的通用代码,但它对我不起作用,在使用引导模式弹出窗口时有什么方法可以做到这一点。

 $('#buttonB').click(function() { alert('test'); $('#buttonA').hide(); });

If #buttonB is a dynamically created element then use jQuery's .on() function in the following format: $(staticAncestors).on(eventName, dynamicChild, function() {});如果#buttonB是动态创建的元素,则使用jQuery 的.on()函数,格式如下: $(staticAncestors).on(eventName, dynamicChild, function() {});

StaticAncestors would be the closest parent element that is static. StaticAncestors 将是最接近的静态父元素。

$(staticAncestors).on('click', '#buttonB', function() {
  alert('test');
  $('#buttonA').hide();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM