2016年4月12日
javascript
document.write 和writeln区别
document.write():将内容写入文档,当前编辑位置为写入的内容的后一个字符。 document.writeln():将内容写入文档,并添加一个换行符,当前编辑位置为写入的内容的后一行的的起始位置。
with(window.open()){
document.write("百度")
document.write("百度")
document.write("百度")
document.writeln("知道")
document.writeln("知道")
document.writeln("知道")
}
效果
百度百度知道
知道
知道
for in循环与for循环
for...in 语句用于对数组或者对象的属性进行循环操作。
语法:
for (变量 in 对象)
{
在此执行代码
}
for循环是对数组的元素进行循环,而不能引用于非数组对象。
语法:
for(int 变量初始值;条件;递增或递减){
在此执行代码
}
类型转换
Number函数
数值:转换后还是原来的值。
字符串:如果可以被解析为数值,则转换为相应的数值,否则得到NaN。空字符串转为0。
布尔值:true转成1,false转成0。
undefined:转成NaN。
null:转成0。
Number("324") // 324
Number("324abc") // NaN
Number("") // 0
Number(false) // 0
Number(undefined) // NaN
Number(null) // 0
String函数:强制转换成字符串
数值:转为相应的字符串。
字符串:转换后还是原来的值。
布尔值:true转为“true”,false转为“false”。
undefined:转为“undefined”。
null:转为“null”。
String(123) // "123"
String("abc") // "abc"
String(true) // "true"
String(undefined) // "undefined"
String(null) // "null"
Boolean函数:强制转换成布尔值
undefined null -0 +0 NaN ’‘(空字符串)
Boolean(undefined) // false
Boolean(null) // false
Boolean(0) // false
Boolean(NaN) // false
Boolean('') // false
angular
标签指令
< a>
会阻止默认行为
< select>
ng-options
for in
<!-- 循环数组对象 -->
<select ng-options="names.name for names in colors" ng-model="tn"></select>
<!-- 循环数组 -->
<select ng-options="names for names in name" ng-model="tn2"></select>
$scope.activities =
[
{ id: 1, type: "Work", name: "Writing code" },
{ id: 2, type: "Work", name: "Testing code" },
{ id: 3, type: "Work", name: "Fixing bugs" },
{ id: 4, type: "Play", name: "Dancing" }
];
<select ng-model="engineer.currentActivity"
data-ng-options="a.name group by a.type for a in activities">
</select>
必须要有ng-model
,这样才能加载数据。
< textarea>
< input>
可以添加表单认证。
< form>
novalidate
阻止表单默认的验证样式
ngularJs的表单验证
表单验证通过才通过双向数据绑定刷新视图。
$valid
数据有效返回true
$invalid
数据无效返回true
$pristine
是否为原始值,是就返回true
$dirty
修改后返回true。
$error
验证失败就会返回错误信息。
注意点
name的方式进行查找
要写ng-model
equired
必填,false表示验证通过。
g-minlength
最小长度,通过为false。
g-maxlength
最大长度,通过为false。
g-pattern
匹配正则,通过为false。
<form novalidate name="myForm">
<input type="email" name="myText" ng-model="text" required ng-minlength="5" ng-pattern="/^[a-zA-Z]+$/">
<div> myForm.myText.$valid:{{ myForm.myText.$valid }}</div>
<div>myForm.myText.$invalid :{{ myForm.myText.$invalid }}</div>
<div>myForm.myText.$pristine:{{ myForm.myText.$pristine }}</div>
<div> myForm.myText.$dirty :{{ myForm.myText.$dirty }}</div>
<div>myForm.myText.$error :{{ myForm.myText.$error }}</div>
</form>
添加class
.ng-valid{}
.ng-invalid{}
.ng-pristine{}
.ng-dirty{}
.txt.ng-valid{ border:1px green solid; background:#e55;}
.txt.ng-invalid{ border:1px red solid; background:blue;}
Last updated
Was this helpful?