2016-09-26 44 views
0

我想在我的html頁面上使用這部分代碼,它工作正常,但我不明白如何更正驗證器上的錯誤。我把函數放在div中,但是在a中我們有同樣的錯誤。這裏是stackoverflow question的鏈接。ontouchend屬性有驗證錯誤,但工作正常

這是驗證錯誤:

Error: Attribute ontouchend not allowed on element div at this point.

這裏是CSS代碼:

:hover { 
    background: red; 
} 

在JS,我有:

function fix() { 
    var el = this; 
    var par = el.parentNode; 
    var next = el.nextSibling; 
    par.removeChild(el); 
    setTimeout(function() { 
     par.insertBefore(el, next); 
    }, 0); 
} 

然後在我的HTML我有:

<a href="#" ontouchend="this.onclick=fix">test</a> 
+0

這部分對我來說似乎很腥:'this.onclick = fix'你在這裏想達到什麼目的? – jmargolisvt

+0

我有一個懸停在iPhone,iPad上,當我點擊一個鏈接,CSS懸停保持活動,與此功能,我可以刪除CSS當我觸摸屏幕 – coolio83000

回答

0

ontouchend屬性不是標準化的。它甚至沒有得到廣泛的支持。這意味着你可以在一些瀏覽器中使用它,但驗證器會發出警告。

當它適用於您時,您可以簡單地忽略它。但這並不意味着這種屬性行爲在未來不會改變。

行情:

This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for the proper prefixes to use in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the spec changes.


Note: This attribute has not been formally standardized. It is specified in the Touch Events – Level 2 Editor's Draft specification and not in Touch Events Recommendation. This attribute is not widely implemented.

瞭解更多關於在MDN文檔herehere屬性。

+0

ahh好吧我明白現在,有一個安全的方法來獲得相同的結果? – coolio83000

+0

嗯,我其實不知道一個。也許是一個JS庫或其他東西。但實際上觸摸事件不是標準化的,也就是說,沒有*默認方式*。對不起。 @ coolio83000 – eisbehr

+0

是的,我認爲這是一個簡單的問題,但我認爲我使用2小時找到一種方式,所以我必須讓css活躍在觸摸屏上!現在沒有辦法解決它!感謝您的幫助@eisbehr – coolio83000