繁体   English   中英

jQuery的:添加HTML文本

[英]Jquery: add html to text

我有一些用于根据IF语句插入一些文本的jquery,它可以正常工作,但是现在我需要向该文本添加一个新类来设置其样式,但是当我这样做时,它不会呈现任何内容。

现有的工作脚本。

      $(document).ready(function(){
        if($('.productdetail').length){
        }else{
       document.getElementById('listwrapper').innerHTML = "Sorry! Your search found no products, please adjust your filters. If you need help call (02) 9620 2424."
         } 
      });

我做了什么,打破了它:

      $(document).ready(function(){
        if($('.productdetail').length){
        }else{
       document.getElementById('listwrapper').innerHTML = "<span class='sorry'>Sorry! Your search found no products, please adjust your filters. If you need help call (02) 9620 2424.</span>"
         } 
      });

任何建议或帮助都很棒!

在jquery中使用.html()

$(document).ready(function(){
        if($('.productdetail').length){
        }
        else{
              $('#listwrapper').html("<span class='sorry'>Sorry! Your search found no products, please adjust your filters. If you need help call (02) 9620 2424.</span>");
         } 
 });

这样使用。

 $(document).ready(function(){
    if($('.productdetail').length){
    }else{
   document.getElementById('listwrapper').html("<span class='sorry'>Sorry! Your search found no products, please adjust your filters. If you need help call (02) 9620 2424.</span>");}
  });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM