2016-09-23 77 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因此,'如果'在一开始......(我同意你的观点,需要先澄清) –