使用css更改文本输入的值? [英] Change a text input's value with css?
问题描述
有没有用css更改文本输入的值(显示的默认文本)?
Is there anyway to change a text input's value (the default text that displays) with css?
假设某个网站为移动网站,我想将搜索此网站缩短为搜索。感谢
Im optomizing a site for mobile and I want the text 'search this site' to be shortened to 'search'. Thanks
推荐答案
这不是CSS的用途。
CSS是为你的内容造型; HTML是针对实际内容本身的。
CSS is for styling your content; HTML is for the actual content itself.
如果您需要在加载HTML后修改内容,那么这就是Javascript的用途。
If you need to modify the content after the HTML has loaded, then that's what Javascript is for.
因此,你的问题的真正答案是:直接修改HTML,或使用Javascript。
So the real answer to your question is: either modify the HTML directly, or use Javascript.
可以使用影响内容的CSS,例如使用:之前
和在元素前面或后面添加额外的文本, :之后
伪选择器,但这不会帮助你在这种情况下,不应该用于你正在谈论的那种内容改变工作。
There are some things you can do with CSS that affect the content, such as adding additional text in-front of or behind an element using the :before
and :after
pseudo-selectors, but that won't help you in this case, and shouldn't be used for the kind of content change work that you're talking about.
顺便说一句,稍微偏离主题,但如果你使用输入字段值作为提示文本,你可能需要考虑看看<占位符
属性。这也不解决你的问题,但它听起来似乎可能是对你有用的东西。
By the way, slightly off-topic, but if you're using input field value as a prompt text, you may want to consider looking into the HTML5 placeholder
attribute instead. This also doesn't address your question, but it does sound like it might be something that could be useful to you.
这篇关于使用css更改文本输入的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!