[英]How to show style="display:none" div element permanently?
I want to show a display:none
element on a click of anchor tag
using jQuery show()
function.我想使用jQuery
show()
函数在单击anchor tag
display:none
元素。
But it's showing the div
element for a moment and then vanished I used return false
and preventDefault
functions but it stops the redirection of anchor tag to a certain page.但它显示了
div
元素一会儿然后消失了我使用了return false
和preventDefault
函数,但它停止了将锚标记重定向到某个页面。
How I can solve this?我该如何解决这个问题?
<div id="assetlist" style="display:none">
@{
Html.RenderPartial("~/Views/Asset/_Asset_List.cshtml");
}
<!-- /.sidebar-menu -->
</div>
<script>
$(document).ready(function () {
$(".asset_managment").click(function(){
$("#assetlist").show();
});
});
</script>
<li class="nav-link" >
<a href="@Url.Action("Index", "Asset")" class="asset_managment">
<img class="img_position" src="@Url.Content("~/admin-lte/img/asset_managment_icon.png")" width="50" height="50" /> Asset Managment
</a>
</li>
Could you just try:你能不能试试:
$(document).ready(function () {
$(".asset_managment").click(function(){
$("#assetlist").attr('style', 'display:block !important');
});
});
this is just gonna overwrite the display property of your div's inline style.这只会覆盖 div 内联样式的显示属性。 hope this helps
希望这可以帮助
You can do like this你可以这样做
$(document).ready(function() { $(".asset_managment").on('click', function(e) { e.preventDefault(); $("#assetlist").show(); }); });
<div id="assetlist" style="display:none"> Show me </div> <li class="nav-link" > <a href="anything" class="asset_managment"> click me </a> </li> <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.