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循环是对数组的元素进行循环,而不能引用于非数组对象。

类型转换

Number函数

数值:转换后还是原来的值。

字符串:如果可以被解析为数值,则转换为相应的数值,否则得到NaN。空字符串转为0。

布尔值:true转成1,false转成0。

undefined:转成NaN。

null:转成0。

String函数:强制转换成字符串

数值:转为相应的字符串。

字符串:转换后还是原来的值。

布尔值:true转为“true”,false转为“false”。

undefined:转为“undefined”。

null:转为“null”。

Boolean函数:强制转换成布尔值

undefined null -0 +0 NaN ’‘(空字符串)

angular

标签指令

  • < a>

    • 会阻止默认行为

  • < select>

    • ng-options

      • for in

必须要有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。

  • 添加class

    • .ng-valid{}

    • .ng-invalid{}

    • .ng-pristine{}

    • .ng-dirty{}

Last updated

Was this helpful?