嗨,我的代码需要帮助才能使下面的 html 折叠,因为它当前不会折叠
这是javascript函数代码
function(event, ui) {
html='';
var show = "Yes";
html += "<h5 id='collapsible'>"+ show +"</h5>";
};
$('#history').html(html);
这是在 html 页面上显示 Yes 的 html 文本代码
<div id="history"></div>
请帮我切换/折叠
<div id="history"></div>
如果您已经在使用 jQuery,则只需使用
toggle()
:
$("#history").toggle();
您可以使用 javascript 方法来实现此目的:
function toggle() {
var target = document.getElementById("history");
if(target.style.display == 'block'){
target.style.display = 'none';
}
else {
target.style.display = 'block';
}
要默认折叠 HTML,请设置属性:
<div id="history" style="display:none;"></div>
Javascript:
$('#collapseHistory').on('click', function(){
$("#history").toggle();
});
HTML:
<div id="history" style="display: none;"></div>
<div id="collapseHistory">Show/Hide</div>
这应该有效
jQuery 版本:
http://www.codepen.io/anon/pen/xBdkl
<div id="temp" onClick="javascript:func()">Show/Hide</div>
<p/>
<div id="history"></div>
<script>
var html='';
var show = "Yes";
html += "<h5 id='collapsible'>"+ show +"</h5>";
$('#history').html(html);
var func = function(){
if($("#history").is(":visible")){
$('#history').hide();
}else{
$('#history').show();
}
}
</script>
我用的是塌陷法
.collapse('hide');
如图所示: