[英]CSS How Do I Make the Text Inside Of a Textfield Unselectable (until first character entered) and Have A Left Margin Of 5px
I want to replicate the sign up form the way google has it: https://accounts.google.com/SignUp?continue=http%3A%2F%2Fwww.google.ca%2F&hl=en But I do not know how to turn the text inside the field unselectable. 我想以谷歌的方式复制注册表单: https : //accounts.google.com/SignUp?continue = http% 3A%2F%2Fwww.google.ca%2F &hl =但我不知道怎么做翻译字段内的文字无法选择。 Here is the rub: I have to make textfield editable so I can't use readonly.
这是擦:我必须使文本域可编辑,所以我不能使用readonly。 See the link please if you need clarification.
如果您需要澄清,请查看链接。 Also, I don't know how to give the text inside the field margins
另外,我不知道如何在字段边缘内提供文本
Here is what I have so far: HTML: 这是我到目前为止:HTML:
<input type="text" onkeyup="validateName(this)" id="first" name="firstName" class="nameSignup" value="First">
CSS: #first { color: grey; CSS:#first {color:grey; }
}
Javascript: 使用Javascript:
function validateName(id){
var str = id.value;
if(str == ""){
id.value = "First";
$(id).prop('selectionStart', 0)
.prop('selectionEnd', 0);
//psudo code
turn text grey
turn text unselectable
margin-left: 10px;
}else{
//Pseudo code
erase the default value
turn text black
turn text editable
margin-left: 0px;
check if the character is valid (not @, #, $, etc)
}
}
You can use HTML5 placeholder attribute. 您可以使用HTML5占位符属性。 This is not supported in older browsers though.
但是在旧版浏览器中不支持此功能。
<input type="text" onkeyup="validateName(this)" id="first" name="firstName" class="nameSignup" placeholder="First">
Support For crossBrowser compatibilty probably you can check this 支持对于crossBrowser兼容性,您可以检查一下
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.