javascript基本包装方法

    xiaoxiao2025-02-02  0

    trim() 方法删除前置及后缀的所有空格。

    var stringValue=" hello wolrd "; var trimmedStringValue=stringValue.trim(); alert(stringValue);// hello wolrd alert(trimmedStringValue);//hello world 字符串转换的方法:toLowerCase() 、toLocaleLowerCase() 、toUpperCase() 、toLocaleUpperCase()

    split() 分隔字符串。

    var colorText="red,blue,green,yellow"; var colors1=colorText.split(","); var colors2=colorText.split(",",2); document.write(colors1);//red,blue,green,yellow document.write("<br>"); document.write(colors2);//red,blue localCompare() 比较两个字符串。

    fromCharCode() 方法将字符编码转换成一个字符串。

    Math() 对象

    min() 和 max()

    var max=Math.max(3,54,32,16); var min=Math.min(3,54,32,16); alert(max);//54 alert(min);//3舍入方法:

    Math.ceil() 执行向上舍入

    Math.floor() 执行向下舍入

    Math.round() 执行标准舍入,四舍五入

    random() 方法 返回随机数:值=Math.floor(Math.random()*可能值的总数+第一个可能的值)。

    转载请注明原文地址: https://ju.6miu.com/read-1296003.html
    最新回复(0)