我有一個隱藏的輸入字段,裏面有值,我有下面的代碼。在範圍內(<span class="telephone"> <span>
),我需要顯示隱藏字段值。我認爲我的JavaScript代碼有錯誤..如何在javascript中添加一段html代碼?在javascript中添加html blob
<input type="hidden" name="mobile" value="04323242445"/>
<script>
var dateFrom =new Date(2014, 2, 3);
var dateTo = new Date(2014, 3, 1);
var dateCheck = Date.now();
if((dateCheck < dateFrom) ||(dateCheck >dateTo)){
document.write("
//I need the below text to show up
<div class="virginMobileError">
<br/>
<p class="first">THE OFFER HAS EXPIRED FOR <span class="telephone"> <span> AND THE CUSTOMER CAN NO LONGER REDEEM THEIR GIFT.</p>
<br/>
<p class="second"><span class="rep">Rep script:</span> "Unfortunately all offers have an end date and this one has ended. We can still change you to Virgin Yes Please to
ensure that you can receive future offers from us."</p>
</div>
");
}
'''用'''打開和關閉的機會,它應該工作。 –
您不應該使用'document.write'來創建HTML(某些情況除外)。 –
你應該使用'document.getElementsByClassName('telephone')[0] .innerHTML =「你需要顯示的文本。」而不是'document.write(「」)'; –