zoukankan      html  css  js  c++  java
  • 字符扫描器 #指针扫描 #去除标签

                
                function SSU(template) {
                    //指针
                    this.pos =  0; 
                    //从哪开始剪切
                    this.ssi = (this.prevssi=0); 
                    //result
                    this.result = '';
                    //扫描
                    this.scanUtils = function (tg) {
                        while(template.substring(this.pos).indexOf(tg) != 0 ) {
                            this.pos++;
                            if(this.eos()) {
                                return '';
                            }
                        }
                        console.log("扫描到了,pos="+this.pos);
                        result = template.substring(this.ssi,this.pos);;this.prevssi=this.ssi;; this.pos=(this.ssi=this.pos+tg.length);;;;return result;
                    }
                    //是否还有字符可以扫描
                    this.eos = function (){
                        return (template.length < this.pos)?true:false;
                    }
                    //重置
                    this.init = function() {
                        this.ssi = (this.pos = 0);
                        this.result = '';
                    }
                    //返回上一次的状态
                    this.goBack = function() {
                        this.ssi = (this.pos = this.prevssi);
                    }
                    
                }
            //使用
                var strScaning = new SSU("你好,<span>小明</span>");
                var collection = '';
                while(! strScaning.eos()) {
                    collection+=strScaning.scanUtils("<");;; strScaning.scanUtils(">");
                }
                console.log(collection);
  • 相关阅读:
    脚本
    vim 马哥
    动态删除节点
    动态插入节点
    动态创建内容
    获取html元素内容
    设置元素的属性
    获取元素的属性
    jquery中:input和input的区别
    jQuery选择器总结
  • 原文地址:https://www.cnblogs.com/zjazn/p/14650401.html
Copyright © 2011-2022 走看看