2016-09-23 74 views
-1

我有一個輸入字段
如何刪除默認的文本「請填寫此場」

我需要刪除默認的文本請填寫此領域 我使用jQuery設置標題爲空功能

$('#Form input[type=text]').each(function() { 
    $(this).attr('title', ' '); 
}); 

它工作正常,除IE和Safari。

然後我試圖NOVALIDATE但這隻適用於如果輸入字段的形式爲內

這裏是我的示例代碼

<head runat="server"> 
    <title></title> 
    <style> 


.div2 .grp { 
    position: relative; 
    margin: 0 2%; 
    margin-bottom: 31px !important; 
    line-height: normal !important; 
} 

.div2 input { 
    font-size: 14px; 
    padding: 6px 10px 6px 0 !important; 
    display: block; 
    width: 100%; 
    border: none; 
    border-bottom: 1px solid #757575; 
    background: transparent!important; 
} 

.div2 label { 
    font-size: 14px; 
    font-weight: normal; 
    position: absolute; 
    pointer-events: none; 
    left: 0; 
    top: 10px; 
    transition: .2s ease all; 
    -moz-transition: .2s ease all; 
    -webkit-transition: .2s ease all; 
    color:Black; 
} 

.div1 { 
    width: 14%; 
    padding: 1%; 
    float: left; 
    } 


label { 
    display: inline-block; 
    max-width: 100%; 
    font-weight: bold; 
} 

</style> 
</head> 
<body> 
    <form id="form1" runat="server"> 

     <div class="div1" > 
      <div class='div2'> 
       <div class="grp" id="divFirstName">  
       <input type="text" runat="server" id="TB_TestForm" onclick="TestForm()" onblur="TestForm()" required/> 
       <label>My first name<span class="reqstar">*</span></label> 
       <span class="required"></span> 
      </div> 

     </div> 
    </form> 
</body> 
</html> 
<script> 
    function TestForm() { 
     var html = document.getElementById("divFirstName").style.position; 
     if (html == "relative" || html=="") { 
      document.getElementById("divFirstName").style.position = "inherit"; 
     } 
     else { 
      document.getElementById("divFirstName").style.position = "relative"; 
     } 
    } 
</script> 

請幫

+1

顯示輸入字段的HTML。我假設你正在使用'placeholder'屬性? – RobIII

+0

請向我們展示您的html標記,同時確保您將輸入設置爲空字符串'「」'而不是空格'「」'就像您正在做的那樣 – Ted

+0

'除IE和Safari之外,它工作正常。無論如何,你應該使用'$('#form input [type = text] [title]')。removeAttr('title');' –

回答

0

如果你的HTML元素的使用placeholder屬性你可以使用下面的代碼(不需要香草JS jQuery):

document.getElementById('input').placeholder = '';
<input id="input" type="text" name="fname" placeholder="First name">

注:請提供您的HTML,所以我們可以計算出臨時解決方案爲您服務。

+2

是不是完整的推測缺少html標記? – Ted

+0

這是肯定錯誤的,因爲OP說它適用於除IE和Safari之外的瀏覽器...... –

+0

@Ted因此,'如果'在一開始......(我同意你的觀點,需要先澄清) –