请问您如何通过javascript切换html内容?
例如:
if($sid == 0)
{one html code}
else
{another html code 2}
LESS,jQuery,CSS3等 - 哪种方式更好?
答案 0 :(得分:3)
您应该使用jQuery load
并传回HTML
内容,例如:
if($sid == 0) {
$('#result').load('ajax/test.html', function() {
alert('Load was performed. (sid equals 0');
});
} else {
$('#result').load('ajax/othercontent.html', function() {
alert('Load was performed. (sid is not equal to 0');
});
}
答案 1 :(得分:0)
jQuery旨在以非浏览器特定的方式执行您所要求的(更明显地)。
<html>
<head>
<style>
.hidden { display: none; }
</style>
<script type="text/javascript">
$(function() {
if(somecondition) $('#div1').show();
else $('#div2').show();
});
</script>
</head>
<body>
<div id="div1" class="hidden">...</div>
<div id="div2" class="hidden">...</div>
</body>
</html>
答案 2 :(得分:0)
我不确定是什么
if($sid == 0)
应该是,但如果你想改变html内容,你可以使用
$("#id").html("<span>your html</span>");