我有一個輸入字段
如何刪除默認的文本「請填寫此場」
我需要刪除默認的文本請填寫此領域 我使用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>
請幫
顯示輸入字段的HTML。我假設你正在使用'placeholder'屬性? – RobIII
請向我們展示您的html標記,同時確保您將輸入設置爲空字符串'「」'而不是空格'「」'就像您正在做的那樣 – Ted
'除IE和Safari之外,它工作正常。無論如何,你應該使用'$('#form input [type = text] [title]')。removeAttr('title');' –