网页模糊查询段落

网页模糊查询段落

	可以用于小说查询大段落的网页

代码

// An highlighted block

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    <h1>模糊查询段落</h1>
    <style>
        .blue {
            color: blueviolet;
        }
        .font {
            background-color: white;
        }
        .note {
            font-size: 16px;
            font-weight: 700;
            /*font-style:*/ 
            color: #f60;
            text-indent: -2em;
            
        }
        * {
            text-align: center;
        }
        a {
            text-decoration: none;
        }
        
    </style> 
    </head>
    <body class="font" >
        <div class="note">
            请先选择文件
        </div>
        <div class="blue">
            <a ><input type="file" id="selectFiles" onchange="dealSelectFiles()"  value="选择文件" ></a>
            <a ><input type="button" id="sosuo" value="搜索"/> </a>
            <a ><input type="text" id="text"></a>
        </div>
        
        <ul>
            <textarea id="txt" rows="25" cols="65" style="background:white"  > </textarea>
            <textarea id="txt1" rows="25" cols="65" style="background:white"  > </textarea>
        </ul>
       

        
<script type="text/javascript">

        //打开文件夹
		function dealSelectFiles() {
            var file = document.getElementById("selectFiles").files[0];
            var name = file.name;//读取选中文件的文件名
            var path = document.getElementById("selectFiles").value;//读取选中文件的路径
            
            console.log("文件名:"+name+"大小:"+path);
            //获取读取我文件的File对象
            //alert(title:'hello',content:'success');
            var reader = new FileReader();//这是核心,读取操作就是由它完成.
            reader.readAsText(file);//读取文件的内容,也可以读取文件的URL
            reader.onload = function () {
                //当读取完成后回调这个函数,然后此时文件的内容存储到了result中,直接操作即可
                document.getElementById("txt").value =this.result;
            }
        }


        var oBtn = document.getElementById('sosuo');
        oBtn.onclick = function(){
            document.getElementById("txt1").value =null;
            var  so =  new RegExp(document.getElementById("text").value);//new RegExp()模糊查询的关键
            var txt = document.getElementById("txt").value;
            var arry = txt.split("\n");//以分行做划分
            for(var i=0;i<arry.length;i++){//遍历每一行
                if (so.test(arry[i])) {//模糊查寻
                    document.getElementById("txt1").value = document.getElementById("txt1").value +'\n' +arry[i];//将那一行输出
                }
                
            }
            
        };
</script>

    </body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值