简体   繁体   English

CSS显示属性问题

[英]Issue with CSS display property

I need to show a remove button when something like the edit button is clicked and in normal cases I don't want to show it. 单击诸如编辑按钮之类的按钮时,我需要显示一个删除按钮,在正常情况下,我不想显示该按钮。

In the normal case, the remove button is not showing up, but when we go and place/hover the mouse on the position where that remove button is placed and click it(here we cant see a remove button), all that functionality is happening which will happen when button is clicked. 在正常情况下,“删除”按钮不会显示,但是当我们将鼠标放置/悬停在放置该“删除”按钮的位置并单击它时(此处我们看不到“删除”按钮),所有的功能都在发生单击按钮时会发生这种情况。


When i want to show the remove button, 当我想显示删除按钮时,

<?php if($something){ ?>
<i class="fa fa-times-circle remove"
style="margin-left: 5px; margin-top: 5px;"  
onclick="function('parameter')"></i>
<?php } ?>


When I don't want to show the button, 当我不想显示按钮时,

<?php if($someOTHERthing){ ?>
<i class="fa fa-times-circle remove"
style="margin-left: 5px; margin-top: 5px;display: none"  
onclick="function('parameter')"></i>
<?php } ?>

and JavaScript code when edit button is clicked, 以及单击“编辑”按钮时的JavaScript代码,

$('.remove').css('display', 'inline');

Just assign and remove the click handler using jQuery. 只需使用jQuery分配和删除点击处理程序即可。 It's cleaner than having it in your HTML anyway. 无论如何,它比将其包含在HTML中更为干净。

So when the edit button is clicked, you'll have: 因此,当单击编辑按钮时,您将具有:

$('.remove').css('display', 'inline');
$('.remove').on('click', function () { 
  // Your code here
});

And when the remove button should hide: 并且当删除按钮应该隐藏时:

$('.remove').css('display', 'none');
$('.remove').off('click');

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

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