内容简介:翻译自:https://stackoverflow.com/questions/2836030/adding-css-class-to-all-input-typetext-elements-javascript-css
我想将CSS类应用于我的站点中的每个文本框:
<div class="editor-label">
<label for="FoodType">FoodType</label>
</div>
<div class="editor-field">
<input id="HelpText" name="FoodType" type="text" value="" />
</div>
<p>
<input type="submit" value="Create" />
</p>
我想,嘿!简单.我将添加一个jquery函数来在母版页中找到它们.
<script type="text/javascript">
$(document).ready(function(){
$('input').addClass('textbox');
}
</script>
不幸的是,这也会选择提交按钮.我怎样才能选择具有文本类型属性的输入元素?
另外,这可能完全使用CSS吗?
如果这两种方法都不可能,我想我只需要手动将类添加到我制作的每个文本框中?
AFAIK它是:
$('input[type=text]').addClass('textbox');
您可以在CSS文件中执行类似操作,但这需要更高版本的CSS /取决于您希望使用旧版浏览器的宽度.
请参阅 here 中的属性选择器.请注意:
“Browser support: The only browser that doesn’t support CSS3 attribute selectors is IE6. Both IE7 and IE8, Opera and Webkit- and Gecko-based browsers do. So using them in your style sheet is definitely safe.”
翻译自:https://stackoverflow.com/questions/2836030/adding-css-class-to-all-input-typetext-elements-javascript-css
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Algorithms Illuminated (Part 2)
Tim Roughgarden / Soundlikeyourself Publishing, LLC / 2018-8-5 / USD 17.99
Algorithms are the heart and soul of computer science. Their applications range from network routing and computational genomics to public-key cryptography and machine learning. Studying algorithms can......一起来看看 《Algorithms Illuminated (Part 2)》 这本书的介绍吧!