2012-11-01 21 views
2

我剛從twitter bootstrap開始。使用範圍或輸入元素爲不可編輯的表單域

我想創建一個禁用的表單域。在文檔中,我發現這個片段:

<input type="text" placeholder="Disabled input here..." disabled> 

但是在IE9中佔位符不工作。當我使用value屬性來設置它的工作內容(並覆蓋palceholder文本,這在其他瀏覽器(如chrome)中可用)。

有不使用input元素的另一種方法:

<span class="uneditable-input">Some value here</span> 

這也適用於IE9和Chrome。哪種解決方案更好(與IE8,7(和6)等舊瀏覽器兼容?)

回答

3

IE 7/8/9不支持HTML5佔位符,最好的解決方案必須是使用提供功能的腳本/插件(,當它不存在時

https://github.com/miketaylr/jQuery-html5-placeholder

我也有http://jquery-watermark.googlecode.com/

有很大的經驗,它們都使用HTML5(如果可用),並模擬它,如果它不是。

他們是令人難以置信的簡單易用。要使用水印,例如,只包括它並添加一行到您的document.ready()

$("#my-input").watermark('default text'); 
2

placeholder屬性是HTML5,不適用於許多瀏覽器,尤其是較舊的瀏覽器,這就是爲什麼它在IE9中不起作用(微軟不遵循標準,即使在IE9)。

如果你的問題是,如果一個跨度會比placeholder屬性更兼容,那麼是的,它是一種跨度應該由所有的瀏覽器都支持。

1

你可以使用JavaScript替代去...

<input type="text" placeholder="Disabled input here..." onfocus="this.blur()" /> 
3
<span class="uneditable-input">Some value here</span> 

更好恕我直言..

原因 - 它會在新舊瀏覽器中按預期行事,它不依賴於任何外部腳本,但僅依賴於css風格uneditable-input

當您只需在span標記中回覆您的值,而不是爲什麼使用禁用的表單字段。

3

我發現,當我想用​​的Prepended and appended inputstwitter bootstrap 我必須使用input元素。它不適用於span元素。

實施例:

<div class="input-prepend"> 
    <span class="add-on">@</span> 
    <input class="span2" id="prependedInput" type="text" placeholder="Username"> 
</div> 

<div class="input-append"> 
    <input class="span2" id="appendedInput" type="text"> 
    <span class="add-on">.00</span> 
</div> 

Screenshot

相關問題