|
|
|
|
|
對(duì)于輸入框的字符,如果要求只能輸入小寫(xiě)或大寫(xiě),怎么處理?js實(shí)現(xiàn)?提交到后臺(tái)程序轉(zhuǎn)換?其實(shí)很簡(jiǎn)單,CSS就有這個(gè)功能,一條語(yǔ)句就搞定。
純CSS實(shí)現(xiàn)輸入框字符自動(dòng)轉(zhuǎn)為小寫(xiě)或大寫(xiě)
.lowercase{
text-transform: lowercase;
}
.uppercase{
text-transform: uppercase;
}
.capitalize{
text-transform: capitalize;
}
解釋?zhuān)?/strong>text-transform
屬性控制文本的大小寫(xiě)。這個(gè)屬性會(huì)改變?cè)刂械淖帜复笮?xiě),而不論源文檔中文本的大小寫(xiě)。lowercase
定義字母為小寫(xiě),uppercase
定義字母為大寫(xiě),如果值為 capitalize
,則要對(duì)首字母大寫(xiě)。
<input type="text" class="lowercase">
<input type="text" class="uppercase">
<input type="text" class="capitalize">
解釋?zhuān)?/strong>input
標(biāo)簽使用class的值來(lái)控制文本大小寫(xiě)。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>純CSS實(shí)現(xiàn)輸入框字符自動(dòng)轉(zhuǎn)為小寫(xiě)或大寫(xiě)</title>
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.css">
<style type="text/css">
.lowercase{
text-transform: lowercase;
}
.uppercase{
text-transform: uppercase;
}
.capitalize{
text-transform: capitalize;
}
</style>
</head>
<body>
<div class="container">
<h1 class="page-header text-center">轉(zhuǎn)換輸入框字符</h1>
<div class="row">
<div class="col-sm-4 col-sm-offset-4">
<div class="form-group">
<label for="lowercase">小寫(xiě)</label>
<input type="text" id="lowercase" class="lowercase form-control">
</div>
<div class="form-group">
<label for="uppercase">大寫(xiě)</label>
<input type="text" id="uppercase" class="uppercase form-control">
</div>
<div class="form-group">
<label for="capitalize">首字母大寫(xiě)</label>
<input type="text" id="capitalize" class="capitalize form-control">
</div>
</div>
</div>
</div>
</body>
</html>
解釋?zhuān)篵ootstrap.css不是必須文件,它只是本案例用到的布局設(shè)計(jì)樣式文件。