前端小知识
Bootstrap
表单
状态校验
添加 .has-warning、.has-error 或 .has-success 类到这些控件的父元素即可。任何包含在此元素之内的 .control-label、.form-control 和 .help-block 元素都将接受这些校验状态的样式。
label标签上的for用于与input标签绑定,label的for值与input的id值相同
input标签上的.aria-describedby与其他标签id绑定
<div class="form-group has-success">
<label class="control-label" for="inputSuccess1">Input with success</label>
<input type="text" class="form-control" id="inputSuccess1" aria-describedby="helpBlock2">
<span id="helpBlock2" class="help-block">A block of help text that breaks onto a new line and may extend beyond one line.</span>
</div>
添加额外图标
针对校验状态为输入框添加额外的图标。只需设置相应的 .has-feedback 类并添加正确的图标即可
反馈图标(feedback icon)只能使用在文本输入框 <input class="form-control"> 元素上
图标、
label和输入控件组对于不带有label标签的输入框以及右侧带有附加组件的输入框组,需要手动为其放置反馈图标。为了让所有用户都能访问你的网站,我们强烈建议为所有输入框添加label标签。如果你不希望将label标签展示出来,可以通过添加.sr-only类将其隐藏。如果的确不能添加label标签,请调整反馈图标的top值。对于输入框组,请根据附加组件的实际情况调整right值。向辅助技术设备传递图标的含义为了确保辅助技术- 如屏幕阅读器 - 正确传达一个图标的含义,额外的隐藏的文本应包含在
.sr-only类中,并明确关联使用了aria-describedby的表单控件。或者,以某些其他形式(例如,文本输入字段有一个特定的警告信息)传达含义,例如改变与表单控件实际相关联的<label>的文本。虽然下面的例子已经提到各自表单控件本身的
<label>文本的验证状态,上述技术(使用.sr-only文本 和aria-describedby) )已经包括了需要说明的目的。
<div class="form-group has-success has-feedback">
<label class="control-label" for="inputSuccess2">Input with success</label>
<input type="text" class="form-control" id="inputSuccess2" aria-describedby="inputSuccess2Status">
<span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true"></span>
<span id="inputSuccess2Status" class="sr-only">(success)</span>
</div>
CSS
css属性
text-decoration
// 设置文本的下划线、上划线等修饰属性
text-decoration: none; /*没有文本装饰*/
text-decoration: underline red; /*红色下划线*/
text-decoration: underline wavy red; /*红色波浪形下划线*/
/*全局值*/
text-decoration: inherit;
text-decoration: initial;
text-decoration: unset;
text-align
// 设置文本对齐方式
text-align:center
CSS选择器
| 选择器 | 例子 | 例子描述 | ||
|---|---|---|---|---|
| .class | .intro | 选择 class=”intro” 的所有元素。 | ||
| .class1.class2 | .name1.name2 | 选择 class 属性中同时有 name1 和 name2 的所有元素。 | ||
| .class1 .class2 | .name1 .name2 | 选择作为类名 name1 元素后代的所有类名 name2 元素。 | ||
| #id | #firstname | 选择 id=”firstname” 的元素。 | ||
| * | * | 选择所有元素。 | ||
| element | p | 选择所有 元素。 |
||
| element.class | p.intro | 选择 class=”intro” 的所有 元素。 |
||
| element,element | div, p | 选择所有 元素和所有 元素。 |
||
| element element | div p | 选择 元素内的所有 元素。 |
||
| element>element | div > p | 选择父元素是 的所有 元素。 |
||
| element+element | div + p | 选择紧跟 元素的首个 元素。 |
||
| element1~element2 | p ~ ul | 选择前面有 元素的每个
|
||
| [attribute] | [target] | 选择带有 target 属性的所有元素。 | ||
| [attribute=value] | [target=_blank] | 选择带有 target=”_blank” 属性的所有元素。 | ||
| [attribute~=value] | [title~=flower] | 选择 title 属性包含单词 “flower” 的所有元素。 | ||
| [[attribute\ | =value]](https://www.w3school.com.cn/cssref/selector_attribute_value_start.asp) | [lang\ | =en] | 选择 lang 属性值以 “en” 开头的所有元素。 |
| [attribute^=value] | a[href^=”https”] | 选择其 src 属性值以 “https” 开头的每个 元素。 | ||
| [attribute$=value] | a[href$=”.pdf”] | 选择其 src 属性以 “.pdf” 结尾的所有 元素。 | ||
| [attribute**=value*] | a[href*=”w3schools”] | 选择其 href 属性值中包含 “abc” 子串的每个 元素。 | ||
| :active | a:active | 选择活动链接。 | ||
| ::after | p::after | 在每个 的内容之后插入内容。 |
||
| ::before | p::before | 在每个 的内容之前插入内容。 |
||
| :checked | input:checked | 选择每个被选中的 元素。 | ||
| :default | input:default | 选择默认的 元素。 | ||
| :disabled | input:disabled | 选择每个被禁用的 元素。 | ||
| :empty | p:empty | 选择没有子元素的每个 元素(包括文本节点)。 |
||
| :enabled | input:enabled | 选择每个启用的 元素。 | ||
| :first-child | p:first-child | 选择属于父元素的第一个子元素的每个 元素。 |
||
| ::first-letter | p::first-letter | 选择每个 元素的首字母。 |
||
| ::first-line | p::first-line | 选择每个 元素的首行。 |
||
| :first-of-type | p:first-of-type | 选择属于其父元素的首个 元素的每个 元素。 |
||
| :focus | input:focus | 选择获得焦点的 input 元素。 | ||
| :fullscreen | :fullscreen | 选择处于全屏模式的元素。 | ||
| :hover | a:hover | 选择鼠标指针位于其上的链接。 | ||
| :in-range | input:in-range | 选择其值在指定范围内的 input 元素。 | ||
| :indeterminate | input:indeterminate | 选择处于不确定状态的 input 元素。 | ||
| :invalid | input:invalid | 选择具有无效值的所有 input 元素。 | ||
| :lang(language) | p:lang(it) | 选择 lang 属性等于 “it”(意大利)的每个 元素。 |
||
| :last-child | p:last-child | 选择属于其父元素最后一个子元素每个 元素。 |
||
| :last-of-type | p:last-of-type | 选择属于其父元素的最后 元素的每个 元素。 |
||
| :link | a:link | 选择所有未访问过的链接。 | ||
| :not(selector) | :not(p) | 选择非 元素的每个元素。 |
||
| :nth-child(n) | p:nth-child(2) | 选择属于其父元素的第二个子元素的每个 元素。 |
||
| :nth-last-child(n) | p:nth-last-child(2) | 同上,从最后一个子元素开始计数。 | ||
| :nth-of-type(n) | p:nth-of-type(2) | 选择属于其父元素第二个 元素的每个 元素。 |
||
| :nth-last-of-type(n) | p:nth-last-of-type(2) | 同上,但是从最后一个子元素开始计数。 | ||
| :only-of-type | p:only-of-type | 选择属于其父元素唯一的 元素的每个 元素。 |
||
| :only-child | p:only-child | 选择属于其父元素的唯一子元素的每个 元素。 |
||
| :optional | input:optional | 选择不带 “required” 属性的 input 元素。 | ||
| :out-of-range | input:out-of-range | 选择值超出指定范围的 input 元素。 | ||
| ::placeholder | input::placeholder | 选择已规定 “placeholder” 属性的 input 元素。 | ||
| :read-only | input:read-only | 选择已规定 “readonly” 属性的 input 元素。 | ||
| :read-write | input:read-write | 选择未规定 “readonly” 属性的 input 元素。 | ||
| :required | input:required | 选择已规定 “required” 属性的 input 元素。 | ||
| :root | :root | 选择文档的根元素。 | ||
| ::selection | ::selection | 选择用户已选取的元素部分。 | ||
| :target | #news:target | 选择当前活动的 #news 元素。 | ||
| :valid | input:valid | 选择带有有效值的所有 input 元素。 | ||
| :visited | a:visited | 选择所有已访问的链接。 |
DOM
//setAttribute 设置标签属性
div.setAttribute('order-state', 'canceled');
//getAttribute 获取标签属性
input.getAttribute('id')
//textContent元素内文本
<div id="news">
<h1>Headline!</h1>
<p>Martians attack people!</p>
</div>
<script>
// Headline! Martians attack people!
alert(news.textContent);
</script>
//classList添加单个类
<body class="main page">
<script>
// 添加一个 class
document.body.classList.add('article');
alert(document.body.className); // main page article
</script>
</body>
兄弟节点(Sibling) 是指有同一个父节点的节点。
例如,<head> 和 <body> 就是兄弟节点:
<html>
<head>...</head><body>...</body>
</html>
<body>可以说是<head>的“下一个”或者“右边”兄弟节点。<head>可以说是<body>的“前一个”或者“左边”兄弟节点。
下一个兄弟节点在 nextSibling 属性中,上一个是在 previousSibling 属性中。
可以通过 parentNode 来访问父节点。
例如:
// <body> 的父节点是 <html>
alert( document.body.parentNode === document.documentElement ); // true
// <head> 的后一个是 <body>
alert( document.head.nextSibling ); // HTMLBodyElement
// <body> 的前一个是 <head>
alert( document.body.previousSibling ); // HTMLHeadElement
let div = document.createElement('div');
div.className = "alert";
div.innerHTML = "<strong>Hi there!</strong> You've read an important message."; document.body.append(div);
node.append(...nodes or strings)—— 在node末尾 插入节点或字符串,node.prepend(...nodes or strings)—— 在node开头 插入节点或字符串,node.before(...nodes or strings)—— 在node前面 插入节点或字符串,node.after(...nodes or strings)—— 在node后面 插入节点或字符串,node.replaceWith(...nodes or strings)—— 将node替换为给定的节点或字符串
div置于底部
<div style="position: absolute; z-index: 55; bottom: 5px; text-align: center; overflow: hidden; width: 100%; height: auto;">
<input type="button" value="后续处理" style="width: 350px; height: 45px; color: black;">
</div>
iconfont
普通字体
// 引入字体css、iconfont 加 字体名
<link rel="stylesheet" href="http://at.alicdn.com/t/font_3125574_dg7amy0ak5b.css">
<i class="iconfont icon-sifenkesiwumaomao col-xs-offset-2" style="font-size: 30px;"></i>
彩色字体
// 引入js、添加css、
<script src="https://at.alicdn.com/t/font_3125574_scj6r0fpek.js"></script>
<style>
.icon {
width: 1em;
height: 1em;
vertical-align: -0.15em;
fill: currentColor;
overflow: hidden;
}
</style>
<svg class="icon svg-icon" aria-hidden="true">
<use xlink:href="#icon-yinjianceng"></use>
</svg>







