[英]getting an error there is no attribute “placeholder” in xhtml strict 1.0
I realize that placeholder is html 5 i believe. 我相信我相信占位符是html 5。 Is there an alternative for placeholder?
有替代占位符的方法吗?
I have to use xhtml strict 1.0 it's a requirement. 我必须使用xhtml strict 1.0,这是一项要求。
You are correct, placeholder is new to HTML5 so it's not going to work in XHTML and there is no real equivalent. 没错,占位符是HTML5的新功能,因此它不能在XHTML中使用,也没有真正的等效项。 The only thing I could suggest is setting the "value" equal to the placeholder text, but then the user will have to delete the text before inputting their own.
我唯一可以建议的是将“值”设置为等于占位符文本,但是用户必须在输入自己的文本之前删除该文本。
The only other option would be to somehow mimic placeholder text using javascript. 唯一的其他选择是使用javascript以某种方式模仿占位符文本。
It's very easy with this library . 这个库非常简单。
Just include the library in the <head>
tag of your page (you can also download the file): 只需将库包含在页面的
<head>
标记中(您也可以下载文件):
<script type='text/javascript' src="https://cdn.rawgit.com/jamesallardice/Placeholders.js/master/dist/placeholders.min.js"></script>
And use a placeholder like you would normally do: 像通常那样使用占位符:
<input type="text" placeholder="I have a placeholder!"/>
xhtml DOES support placeholder because XHTML is a mix of XML & HTML. xhtml确实支持占位符,因为XHTML是XML和HTML的混合。 The function works but it won't validate because validation methods haven't caught up with new coding principles.
该功能有效,但由于验证方法尚未赶上新的编码原理,因此无法验证。 Use this as an alternative which does validate;
以此作为验证的替代方法;
<input type="text" onfocus="if (this.value==this.defaultValue) this.value = ''" onblur="if (this.value=='') this.value = this.defaultValue" value="your placeholder text here" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.