【发布时间】:2016-09-23 10:04:16
【问题描述】:
我有一个输入字段
我需要删除默认文本请填写此字段 我使用 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属性? -
请向我们展示您的 html 标记,同时确保您将输入设置为空字符串
""而不是空格" "就像您在上面所做的那样 -
It works fine except IE and Safari.那么浏览器缓存呢?!...无论如何,你应该使用$('#Form input[type=text][title]').removeAttr('title'); -
寻求调试帮助的问题(“为什么这段代码不起作用?”)必须包括所需的行为、特定的问题或错误以及重现所需的最短代码在问题本身。请阅读:minimal reproducible example
-
我不能使用占位符或标题属性,我的输入字段是这样的
标签: javascript jquery google-chrome internet-explorer