2017-02-13 51 views
0

I have this code on a page:如何返回一个div在<a href> with javascript?

<a href="javascript:void(0);" class="remont_price_link">Потолок + </a> 

enter image description here 我需要我的代码来显示一个div,就像'1'一样。 '2' - 它应该在点击之前。

所以我需要DIV“remont_price_link”的弹出当用户 点击这一个不工作:

<a href="javascript:void(0)onclick='popup' ;" class="remont_price_link">Потолок + </a> 

对不起,我傻了。

enter image description here

+0

'popup'是做你想达到的功能吗? –

+0

我不确定,但我认为是。我只需要点击后像图片中的'1'一样返回div。在点击ot之前应该像'2'一样隐藏。 –

+0

发布'popup'函数的代码。另外你有一个轻微的错误,那里的链接应该是:'Потолок +' –

回答

1

添加这个土特产品脚本:

$(".remont_price_link").click(function() { 
    var parent = $(this).parent(); 
    var spoiler = $(this).closest(".remont_price_item").find(".spoiler-text"); 
    if(parent.hasClass("folded")) { 
     parent.removeClass("folded"); 
     spoiler.show(); 
    } 
    else { 
     parent.addClass("folded"); 
     spoiler.hide(); 
    } 
}); 

并保持链接原样。像这样:

<a href="javascript:void(0);" class="remont_price_link">Потолок + </a> 
+0

它的工作原理!谢谢你。 = * –

1

可以显示/隐藏使用CSS '显示' 和JavaScript的DIV。

在这里看到代码:https://codepen.io/cpenarrieta/pen/XpoExe

CSS

.hidden { 
    display: none; 
} 

.show { 
    display: inherit; 
} 

的Javascript

function showDiv() { 
    var x=document.getElementById("divId"); 
    if (x.classList.contains("show")) { 
    x.classList.add('hidden'); 
    x.classList.remove('show'); 
    } else if (x.classList.contains("hidden")) { 
    x.classList.add('show'); 
    x.classList.remove('hidden'); 
    } 
} 

HTML

<a href='javascript:;' onclick='showDiv();'>Потолок +</a> 
<div id="divId" class="hidden"> 
div content 
</div> 
相关问题