2015-02-07 48 views
0

我已經使用html,css和jqueries創建了網頁。佔位符值在IE8中不起作用

我修復了IE8中的最大問題。儘管如此,我仍在掙扎着佔位符價值。

爲此,我試過了,

我加了下面的腳本在我的腦海標籤:

<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery-placeholder/2.0.8/jquery.placeholde‌​r.min.js"></script> 
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> 

並且我增加了輸入結束標記之前:

<script>$('input, textarea').placeholder();</script> 

以上這些腳本放置在我的index.html中。

這是header.html中:

<form action="#" method="get" id="search-form" role="search" class="large--right"> 
     <input name="q" type="text" id="search-field" placeholder="Search store..." class="hint"> 
     <button type="submit" value="" name="submit" id="search-submit" class="icon-fallback-text"> 
     <span class="icon icon-search" aria-hidden="true"></span> 
     <span class="fallback-text">Search</span> 
     </button> 
     </form> 

但它沒有工作,我可以知道,這些都是正確。如果沒有,你可以請給我建議。

在此先感謝。

+0

你在這裏看到什麼錯誤?另外,你的HTML是什麼? – MFazio23 2015-02-07 04:24:18

+0

在'jquery.min.js'之後加載'jquery.placeholde r.min.js'?檢查開發者控制檯是否有錯誤。 – 2015-02-07 04:24:33

+0

@ AlexanderO'Mara:我換了..但仍然保持不變。 – rish 2015-02-07 04:28:50

回答

1

使用THIS插件。

檢查佔位符的演示這裏HERE - >

使用此代碼

<!--[if lte IE 10]> 
     <script type="text/javascript" src="http://linux.aress.net/smudev/js/nwxforms.js"></script>  
     <script type="text/javascript">window.onload = Function('nwxforms(this)');</script> 
    <![endif]--> 

以JS從我的網站。

我建議你從這裏採取JS文件HERE。然後把你的文件夾中,並使用相對路徑,如:

<script type="text/javascript" src="YourjsFolder/nwxforms.js"></script>

+0

其工作正常ie8 ..但我只是困惑,嘗試在我的網頁。 – rish 2015-02-07 04:49:37

+0

可以請你幫我,如何使用..我可以從你的鏈接下載zip文件嗎? – rish 2015-02-07 04:51:43

+0

好@rani mam,我更新答案。 – 2015-02-07 04:52:38

1

當複製您的JS文件到我的本地環境中,我得到了佔位符JS代碼一個非常奇怪的網址:

http://cdnjs.cloudflare.com/ajax/libs/jquery-placeholder/2.0.8/jquery.placeholde%C3%A2%E2%82%AC%C5%92%C3%A2%E2%82%AC%E2%80%B9r.min.js 

嘗試複製此網址(它看起來相同,但也有一些奇怪的字符你的):

//cdnjs.cloudflare.com/ajax/libs/jquery-placeholder/2.0.8/jquery.placeholder.min.js 
+0

是的,我仍然認爲URL佔位符中有一個隱藏的字符。用我發佈的內容更新URL,確保jQuery在佔位符前加載,然後下移到jQuery 1.10.1(由於支持IE8)。這些修復後,我沒有收到任何使用您的代碼的錯誤。 – MFazio23 2015-02-07 04:37:34

+0

你懂了IE8? @ MFazio23 ...是的我更新..still沒有工作.. – rish 2015-02-07 04:38:52

+0

我能做的最好的是在IE8模式IE11。我在jQuery 2.0.8中看到了一個錯誤,但是向下移動到1.10.1(正如@Mr_Green所建議的)擺脫了任何錯誤。 – MFazio23 2015-02-07 04:45:46

1
Try following plugin 

https://github.com/mathiasbynens/jquery-placeholder

if($.browser.msie){ 
    $('input[placeholder]').each(function(){ 

     var input = $(this);   

     $(input).val(input.attr('placeholder')); 

     $(input).focus(function(){ 
      if (input.val() == input.attr('placeholder')) { 
       input.val(''); 
      } 
     }); 

     $(input).blur(function(){ 
      if (input.val() == '' || input.val() == input.attr('placeholder')) { 
       input.val(input.attr('placeholder')); 
      } 
     }); 
    }); 
}; 

Its helpful for you 
+0

呃,我很確定他已經在嘗試使用它... – 2015-02-07 04:42:33

+0

這是我用過的... – rish 2015-02-07 04:44:51

+0

@rani我已經更新了我的答案 – 2015-02-07 04:56:57

1

我不認爲你需要任何jQuery的佔位符這裏插件。

Chrome,Firefox和IE10 +已經支持文本字段的placeholder屬性。

因此,您嘗試佔位符的唯一瀏覽器是IE8和IE9

獲得像設計佔位符的大部分部分可以使用CSS來完成。然後只是觸發按鍵事件,JavaScript是必需的。

這裏是一個demo

CSS

label { 
    position: absolute; 
    z-index: 0; 
    left: 0px; 
    color: #CCC; 
    top: 0px; 
    padding: 2px; 
} 
.input-wrapper { 
    position: relative; 
    display: inline-block; 
} 

HTML

<form action="#" method="get" id="search-form" role="search" class="large--right"> 
    <div class="input-wrapper"> 
     <input name="q" type="text" id="search-field" class="hint"></input> 
     <label id="label-search-field" for="search-field">Search store...</label> 
    </div> 
    <button type="submit" value="" name="submit" id="search-submit" class="icon-fallback-text"> <span class="icon icon-search" aria-hidden="true"></span> 
<span class="fallback-text">Search</span> 

    </button> 
</form> 

的JavaScript

// Include this function 
function placeholder(e, label) { 
    var e = e || window.event; 
    var el = e.currentTarget || e.srcElement; 
    label.style.color = el.value.length ? "transparent" : ""; 
} 


// call like this in your project 
var text = document.getElementById('search-field'); 
text.onkeyup = function (e) { 
    var label = document.getElementById('label-search-field'); 
    placeholder(e, label); 
} 
+0

所以不需要使用nwxforms.js文件嗎? – rish 2015-02-07 05:47:19

+0

@rani我對nwxforms瞭解不多,但我在想如果你只是想在IE8中支持佔位符,那麼現在就不需要nwxforms.js了。 – 2015-02-07 05:52:55

+0

[根據caniuse的說法,IE9不支持'placeholder'屬性](http://caniuse.com/#feat=input-placeholder)。 – 2015-02-07 16:04:33