2016-11-08 44 views
4

我的問題似乎與其他人所遇到的問題相反。我不想讓.innerHTML中的HTML運行。我希望它按原樣顯示在頁面上。 (我知道有一個在我的代碼。我的工作是另一個問題)如何讓我的頁面顯示html而不是運行?

https://jsfiddle.net/ojfykv17/

<div id="code"> 

</div> 

function genorateCode() { 
 
    \t \t var account = document.getElementById("account"); 
 
     var url = document.getElementById("url"); 
 
     sendCode(); 
 
    } 
 
    function sendCode() { 
 
    document.getElementById('code').innerHTML = '<a href="'+url+'">'+'<div class="button"><img src="https://s15.postimg.org/mfpd2ki8r/icon.png" width="16">@'+account+'</div></a>'; 
 
    } 
 
    sendCode();
.button { 
 
    border-radius: 5px; 
 
    background-color: white; 
 
    border:1; 
 
    border-style: solid; 
 
    position: fixed; 
 
    padding: 5px 10px 5px 10px; 
 
    border-width: 1.2px; 
 
    line-height: 5px; 
 
    border-color: #a5aab1; 
 
    font-family: 'Lato', sans-serif; 
 
    font-weight:300; 
 
    text-align: center; 
 
    }
<form id="form" onsubmit="return false;"> 
 
     <input type="text" id="account" /> 
 
     <input type="text" id="url" /> 
 
     <input type="submit" onclick="genorateCode();" /> 
 
    </form> 
 
    
 
    <div id="code"> 
 
    
 
    </div>

+5

你什麼意思,你不希望它運行?你的意思是你想讓它實際顯示標記標籤嗎?如果是這樣,請看這裏:http://stackoverflow.com/questions/2820453/display-html-code-in-html –

+0

這是一個使用'