It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center
6年前关闭。
你能告诉我如何用javascript切换html内容吗?
例如:
if($sid == 0)
 {one html code}
else
 {another html code 2}

LESS、jQuery、CSS3等-哪种方式更好?

最佳答案

您应该使用jQueryload并将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');
  });
}

http://api.jquery.com/load/

关于javascript - 通过javascript切换html内容的最佳方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13375072/

10-12 00:13
查看更多