我有一個外部的javascript檔案,我在里面寫了jquery代碼和javascript代碼,但是javascript代碼不作業,只有警報在作業。
我想讓一些文本閃爍不同的顏色,但它沒有。
當我使用ctrl shift i檢查元素時,我看到顏色在檢查元素下發生了變化,但在網頁上卻沒有變化。
好像它是在后臺運行還是什么,我真的不知道。
。function flash() { var text = document. getElementById('sales'); text.style。 color=(text.style.color=='red') ?'green' : 'red'; } var clr = setInterval(flash, 500)
<p id="sales" /span>>。 <h3 style ="text-align: center; font-weight: bold;"> Flash銷售 </h3></p>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
uj5u.com熱心網友回復:
如果你適當地檢查一下,你會發現你的HTML被改變了,與你的情況不同。一個<p>元素不能包含一個<h3>元素,并且DOM已經被改變為<p id="sales"></p><h3>...</h3>。
因此,你的CSS被應用到了錯誤的地方。
。function flash() { var text = document. getElementById('sales'); text.style。 color=(text.style.color=='red') ?'green' : 'red'; } var clr = setInterval(flash, 500)
< h3 id="sales" style ="text-align: center; font-weight: bold;">閃電銷售 </h3>
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
uj5u.com熱心網友回復:
我通過從<h3標簽中洗掉所有的行內樣式,并在css中對其進行樣式處理,從而解決了這個問題。
uj5u.com熱心網友回復:
在純java腳本中
document. querySelector('element name').style.color = 'red';
在jquery中
$('element name').css({red : 'red'}) 。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/321674.html
標籤:
