简体   繁体   English

收到错误,xhtml严格1.0中没有属性“占位符”

[英]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!"/>

JS Fiddle Demo JS小提琴演示

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.

相关问题 有效的xhtml 1.0严格JS切换,不会出现推测性分析错误 - Valid xhtml 1.0 strict JS toggle without speculative parsing error XHTML 1.0 Strict:表单/ javascript问题 - XHTML 1.0 Strict: Problems with form/ javascript 是否可以在XHTML Strict 1.0中使按钮调用JavaScript函数? - Is it possible to make a button call a JavaScript function in XHTML Strict 1.0? 如何解决XHTML 1.0 Strict中的表单操作问题 - How to fix form action issue in XHTML 1.0 Strict 使用Pinterest hoverbutton但在XHTML 1.0 Strict中禁用某些图像 - Using the Pinterest hoverbutton but disabling it for certain images in XHTML 1.0 Strict Javascript更改marginTop属性在Firefox for XHTML 1.0 Transitional中不起作用 - Javascript changing marginTop attribute not working in Firefox for XHTML 1.0 Transitional TinyMCE正在修改我输入的XHTML 1.0 Strict HTML。 我该如何阻止它? - TinyMCE is modifying the XHTML 1.0 Strict HTML I input. How can I stop it? 严格在Javascript xhtml 1.0中验证表单数据,而不为此实例考虑服务器端脚本 - Validating form data in Javascript xhtml 1.0 strict, not considering server side scripts for this instance document.write XHTML 1.0过渡验证错误 - document.write XHTML 1.0 Transitional validation error Javascript:出现“使用严格”错误 - Javascript : Getting 'Use Strict' error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM