簡體   English   中英

javascript attr類型IE9

[英]javascript attr type IE9

出於某些原因,IE9在編寫以下代碼時返回“文本”。任何想法。 其他瀏覽器返回電子郵件

的HTML

<input type="email">

javascript

alert($(input).attr('type'))

這是因為IE9不支持電子郵件,因此它會忽略這些值並將其重置為它支持的默認值。

出於某些原因,IE9在編寫以下代碼時返回“文本”。任何想法。 其他瀏覽器返回電子郵件

的HTML

在符合W3C標准的瀏覽器中(其中element是對input元素的引用),然后:

// Get the value of the HTML type attribute
element.getAttribute('type') // email

// Get the value of the DOM type property
element.type                 // email or text, depending on whether 
                             // type email is supported or not

getAttribute返回關聯屬性的文字值。 DOM屬性返回DOM屬性設置為的實際值(它們可能是並且經常是不同的值)。 IE 9符合標准-它不支持電子郵件,因此DOM屬性返回“文本”,而getAttribute返回“電子郵件”。

javascript

  alert($(input).attr('type')) // email in jQuery version 1.6 and higher alert($(input).prop('type')) // text in jQuery version 1.6 and higher 

根據jQuery文檔attr方法返回屬性值,並且在1.6及更高版本中使用。 要獲取DOM屬性,請使用prop 在此之前,jQuery作者試圖再次猜測開發人員的實際需求,而attr根據無法解釋的邏輯返回了屬性或DOM屬性值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM