mwwdfl 发布的文章

<script type="text/javascript">
    /**
     * 到底加载
     */
    var flag=1;
    var rgb = 0;
    $(window).bind("scroll", function () {
        if(getScrollHeight() < getDocumentTop() + getWindowHeight() + 250){ //+200是底部,到250留点距离
            //当滚动条到底时,这里是触发内容
            //异步请求数据,局部刷新dom
            pageNum++;
            //ajax_function()
//            if (flag == 1) {
//                flag=0;
//                var temp = `<div style="height:500px; background:rgb(100,${rgb},${rgb});"></div>`;
//                $('body').append(temp);
//                rgb = rgb + 20;
//                flag = 1;
//            }
        }
    });

    //文档高度
    function getDocumentTop() {
        var scrollTop =  0, bodyScrollTop = 0, documentScrollTop = 0;
        if (document.body) {
            bodyScrollTop = document.body.scrollTop;
        }
        if (document.documentElement) {
            documentScrollTop = document.documentElement.scrollTop;
        }
        scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;
        console.log("scrollTop:"+scrollTop);
        return scrollTop;
    }

    //可视窗口高度
    function getWindowHeight() {
        var windowHeight = 0;
        if (document.compatMode == "CSS1Compat") {
            windowHeight = document.documentElement.clientHeight;
        } else {
            windowHeight = document.body.clientHeight;
        }
        console.log("windowHeight:"+windowHeight);
        return windowHeight;
    }

    //滚动条滚动高度
    function getScrollHeight() {
        var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0;
        if (document.body) {
            bodyScrollHeight = document.body.scrollHeight;
        }
        if (document.documentElement) {
            documentScrollHeight = document.documentElement.scrollHeight;
        }
        scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
        console.log("scrollHeight:"+scrollHeight);
        return scrollHeight;
    }
</script>

/***
     * @return \think\response\Json
     * 更新城市json数据
     */
    public function makejsonareas(){
        set_time_limit(0);
        $pro = Db::table('up_area')
            ->where('level',1)
//            ->where('district_id',1001)
            ->field('district_id id,district name')
            ->select();
        $shi = Db::table('up_area')
            ->where('level',2)
            ->field('district_id id,district name,pid parentId')
            ->select();
        $qu = Db::table('up_area')
            ->where('level',3)
            ->field('district_id id,district name,pid parentId')
            ->select();
        $street = Db::table('up_area')
            ->where('level',4)
            ->field('district_id id,district name,pid parentId')
            ->select();
        foreach ($qu as $k=>$v){
            foreach ($street as $kk=>$vv){
                if($vv['parentId'] == $v['id']){
                    $qu[$k]['sub'][] = $vv;
                }
            }
        }
        foreach ($shi as $k=>$v){
            foreach ($qu as $kk=>$vv){
                if($vv['parentId'] == $v['id']){
                    $shi[$k]['sub'][] = $vv;
                }
            }
        }
        foreach($pro as $k=>$v){
            $pro[$k]['parentId'] = 0;
            foreach ($shi as $kk=>$vv){
                if($vv['parentId'] == $v['id']){
                    $pro[$k]['sub'][] = $vv;
                }
            }
        }
        $root = $_SERVER['DOCUMENT_ROOT'];
        $myfile = fopen("$root/static/test.json", "w") or die("Unable to open file!");
        $txt = json_encode($pro);
        fwrite($myfile, $txt);
        fclose($myfile);
        return json(['code' => 200, 'msg' => '更新成功']);
    }

function is_idcard( $id )
    {
        $id = strtoupper($id);
        $regx = "/(^\d{15}$)|(^\d{17}([0-9]|X)$)/";
        $arr_split = array();
        if(!preg_match($regx, $id))
        {
            return FALSE;
        }
        if(15==strlen($id)) //检查15位
        {
            $regx = "/^(\d{6})+(\d{2})+(\d{2})+(\d{2})+(\d{3})$/";

            @preg_match($regx, $id, $arr_split);
            //检查生日日期是否正确
            $dtm_birth = "19".$arr_split[2] . '/' . $arr_split[3]. '/' .$arr_split[4];
            if(!strtotime($dtm_birth))
            {
                return FALSE;
            } else {
                return TRUE;
            }
        }
        else      //检查18位
        {
            $regx = "/^(\d{6})+(\d{4})+(\d{2})+(\d{2})+(\d{3})([0-9]|X)$/";
            @preg_match($regx, $id, $arr_split);
            $dtm_birth = $arr_split[2] . '/' . $arr_split[3]. '/' .$arr_split[4];
            if(!strtotime($dtm_birth)) //检查生日日期是否正确
            {
                return FALSE;
            }
            else
            {
                //检验18位身份证的校验码是否正确。
                //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
                $arr_int = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
                $arr_ch = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
                $sign = 0;
                for ( $i = 0; $i < 17; $i++ )
                {
                    $b = (int) $id{$i};
                    $w = $arr_int[$i];
                    $sign += $b * $w;
                }
                $n = $sign % 11;
                $val_num = $arr_ch[$n];
                if ($val_num != substr($id,17, 1))
                {
                    return FALSE;
                }
                else
                {
                    return TRUE;
                }
            }
        }

    }
$idc=is_idcard("身份证号码"); 
if($idc){echo "正确";}else{echo "错误";}

input输入框实时显示计算,不能有多余的.,结果保留两位小数

<input id="task_num" type="text" oninput = "handleMoney(this,0);">
<input id="task_price" type="text" oninput = "handleMoney(this,1);">
function handleMoney(obj,type){//0代表不要小数,1代表代表保留两位小数
        if(type == 0){
            obj.value = obj.value.replace(/[^\d]/g, '');//没有.
            obj.value = obj.value.replace(/\.{2,}/g, '.');
            obj.value = obj.value.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.');
            //(\d\d)代表保留两位,(\d)代表保留一位,以此类推....
            obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
            if (obj.value.indexOf('.') < 0 && obj.value != '') {
                obj.value = parseFloat(obj.value);
            }
            if ((obj.value.length == 1 && obj.value == '.') || obj.value.substring(0,1) == '.') {
                obj.value = '';
            }
        }else{
            obj.value = obj.value.replace(/[^\d.]/g, '');//有.
            obj.value = obj.value.replace(/\.{2,}/g, '.');//2即两位
            obj.value = obj.value.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.');
            obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
            if (obj.value.indexOf('.') < 0 && obj.value != '') {
                obj.value = parseFloat(obj.value);
            }
            if ((obj.value.length == 1 && obj.value == '.') || obj.value.substring(0,1) == '.') {
                obj.value = '';
            }
        }

        var value1 = $('#task_num').val();
        var value2 = $('#task_price').val();
        if(value1 && value2){
            var res = value1*value2;
            $('#money').val(res.toFixed(2));
        }else{
            $('#money').val(0);
        }
    }

public function pingyinFirstChar($sourcestr)
    {

        $returnstr = '';
        $i = 0;
        $n = 0;
        $str_length = strlen($sourcestr);//字符串的字节数

        while ($i <= $str_length) {

            $temp_str = substr($sourcestr, $i, 1);
            $ascnum = Ord($temp_str);//得到字符串中第$i位字符的ascii码

            if ($ascnum >= 224) { //如果ASCII位高与224,
                $returnstr = $returnstr . $this->getHanziInitial(substr($sourcestr, $i, 3)); //根据UTF-8编码规范,将3个连续的字符计为单个字符
                $i = $i + 3;//实际Byte计为3
            } else if ($ascnum >= 192) { //如果ASCII位高与192,
                $returnstr = $returnstr . $this->getHanziInitial(substr($sourcestr, $i, 2)); //根据UTF-8编码规范,将2个连续的字符计为单个字符
                $i = $i + 2;//实际Byte计为2
            } else if ($ascnum >= 65 && $ascnum <= 90) { //如果是大写字母,
                $returnstr = $returnstr . substr($sourcestr, $i, 1);
                $i = $i + 1;//实际的Byte数仍计1个
            } else { //其他情况下,包括小写字母和半角标点符号,
                $returnstr = $returnstr . strtoupper(substr($sourcestr, $i, 1)); //小写字母转换为大写
                $i = $i + 1;//实际的Byte数计1个
            }
        }

        return $returnstr;
    }

    public function getHanziInitial($s0)
    {

        if (ord($s0) >= "1" and ord($s0) <= ord("z")) {
            return strtoupper($s0);
        }
        $s = iconv("UTF-8", "gb2312//IGNORE", $s0); // 不要转换成GB2312内没有的字符哦,^_^
        // var_dump($s);exit;

        $asc = @ord($s[0]) * 256 + @ord($s[1]) - 65536;
        if ($asc >= -20319 and $asc <= -20284) return "A";
        if (in_array($asc, [])) return "A";
        if ($asc >= -20283 and $asc <= -19776) return "B";
        if (in_array($asc, [-8791, -5941])) return "B";
        if ($asc >= -19775 and $asc <= -19219) return "C";
        if (in_array($asc, [-4916])) return "C";
        if ($asc >= -19218 and $asc <= -18711) return "D";
        if (in_array($asc, [])) return "D";
        if ($asc >= -18710 and $asc <= -18527) return "E";
        if (in_array($asc, [])) return "E";
        if ($asc >= -18526 and $asc <= -18240) return "F";
        if (in_array($asc, [-6662])) return "F";
        if ($asc >= -18239 and $asc <= -17923) return "G";
        if (in_array($asc, [-8721, -2824, -5681])) return "G";
        if ($asc >= -17922 and $asc <= -17418) return "H";
        if (in_array($asc, [-8721])) return "H";
        if ($asc >= -17417 and $asc <= -16475) return "J";
        if (in_array($asc, [-5671, -8795, -65536, -8966, -8772, -6712])) return "J";
        if ($asc >= -16474 and $asc <= -16213) return "K";
        if (in_array($asc, [])) return "K";
        if ($asc >= -16212 and $asc <= -15641) return "L";
        if (in_array($asc, [-2069, -5715])) return "L";
        if ($asc >= -15640 and $asc <= -15166) return "M";
        if (in_array($asc, [-8786, -7512])) return "M";
        if ($asc >= -15165 and $asc <= -14923) return "N";
        if (in_array($asc, [])) return "N";
        if ($asc >= -14922 and $asc <= -14915) return "O";
        if (in_array($asc, [])) return "O";
        if ($asc >= -14914 and $asc <= -14631) return "P";
        if (in_array($asc, [-8718, -5951])) return "P";
        if ($asc >= -14630 and $asc <= -14150) return "Q";
        if (in_array($asc, [-2072, -8967])) return "Q";
        if ($asc >= -14149 and $asc <= -14091) return "R";
        if (in_array($asc, [])) return "R";
        if ($asc >= -14090 and $asc <= -13319) return "S";
        if (in_array($asc, [-8744, -8795])) return "S";
        if ($asc >= -13318 and $asc <= -12839) return "T";
        if (in_array($asc, [-8979])) return "T";
        if ($asc >= -12838 and $asc <= -12557) return "W";
        if (in_array($asc, [-8789])) return "W";
        if (in_array($asc, [-4869, -9016, -8529])) return "X";
        if ($asc >= -12556 and $asc <= -11848) return "X";
        if ($asc >= -11847 and $asc <= -11056) return "Y";
        if (in_array($asc, [-5930, -5159])) return "Y";
        if ($asc >= -11055 and $asc <= -10247) return "Z";
        if (in_array($asc, [-5717])) return "Z";
        return 'a'; //$s0 是 返回原字符,不作转换。(标点、空格、繁体字都会直接返回)
    }