代码之家  ›  专栏  ›  技术社区  ›  Bojan Kolano

不使用javascript在JSON项中注册粗体文本

  •  1
  • Bojan Kolano  · 技术社区  · 8 年前

    所以我有一个列表,上面的项目用粗体标出年份。但是当我将它们放在JSON中,稍后我将文本设置为HTML时,文本不是粗体。在链接中,现在我有了粗体标签和文本。这让人困惑。我能做这个吗?

    <div class="year-list">
            <h3 class="time-line">Here's a time line of Dr. Borlaug's life:</h3>
            <div class="big-list">
                <ul>
                    <li></li>
                    <li></li>
                    <li></li>
                    <li></li>
                    <li><b>1938 </b> - Marries wife of 69 years Margret Gibson. Gets laid off due to budget cuts. Inspired by Elvin Charles Stakman, he returns to school study under Stakman, who teaches him about breeding pest-resistent plants.</li>
                    <li><b>1941 </b> - Tries to enroll in the military after the Pearl Harbor attack, but is rejected. Instead, the military asked his lab to work on waterproof glue, DDT to control malaria, disenfectants, and other applied science.</li>
                    <li><b>1942 </b> - Receives a Ph.D. in Genetics and Plant Pathology</li>
                    <li><b>1944 </b> - Rejects a 100% salary increase from Dupont, leaves behind his pregnant wife, and flies to Mexico to head a new plant pathology program. Over the next 16 years, his team breeds 6,000 different strains of disease resistent wheat - including different varieties for each major climate on Earth.</li>
                    <li><b>1945 </b> - Discovers a way to grown wheat twice each season, doubling wheat yields</li>
                    <li><b>1953 </b> - crosses a short, sturdy dwarf breed of wheat with a high-yeidling American breed, creating a strain that responds well to fertalizer. It goes on to provide 95% of Mexico's wheat.</li>
                    <li><b>1962 </b> - Visits Delhi and brings his high-yielding strains of wheat to the Indian subcontinent in time to help mitigate mass starvation due to a rapidly expanding population</li>
                    <li><b>1970 </b> - receives the Nobel Peace Prize</li>
                    <li><b>1983 </b> - helps seven African countries dramatically increase their maize and sorghum yields</li>
                    <li><b>1984 </b> - becomes a distinguished professor at Texas A&M University</li>
                    <li><b>2005 </b> - states "we will have to double the world food supply by 2050." Argues that genetically modified crops are the only way we can meet the demand, as we run out of arable land. Says that GM crops are not inherently dangerous because "we've been genetically modifying plants and animals for a long time. Long before we called it science, people were selecting the best breeds."</li>
                    <li></li>
                </ul>
            </div>
        </div>
    

    这是我的JSON的一部分。

    {"divHoldingTitle":{"title":"Dr. Norman Borlaug","textSave":"The man who saved a billion lives"},"imageHolder":{"theBigPicture":"./images/smiling-people.jpg","textUnderPicture":"Dr. Norman Borlaug, second from left, trains biologists in Mexico on how to increase wheat yields - part of his life-long war on hunger."},"bigList":{"itemList":[{"item":"<b>1914 </b> - Born in Cresco, Iowa"},{"item":"<li><b>1933 </b> - Leaves his family\'s farm to attend the University of Minnesota, thanks to a Depression era program known as the\'National Youth Administration\'"}]}}
    
     for(i in obj.bigList.itemList){
    
        $('li').text(obj.bigList.itemList[i].item);
    }
    

    }(二)

    问题是这个。

    Screenshot of the problem

    如你所见。名单上有

  • 1933年 -把家里的农场留给…… 但它不是大胆的。

    我不知道如何解决这个问题。我正在使用javascript。

  • 1 回复  |  直到 8 年前
        1
  •  0
  •   Alex S.    8 年前

    这是由于使用了.text()方法-它删除了所有格式标记。 改用html():

    $('li').html(obj.bigList.itemList[i].item);