zoukankan      html  css  js  c++  java
  • aspx页面中<input>中特殊字符导致提交不安全信息问题的解决方案

    在页面中的input标签中提交特殊字符,如&," 符号,后台文件在接受数据时会认为是不安全的输入内容,引起黄页异常,解决方案如下:

    aspx文件代码:

    <input type="text" id="txtFooterName" name="txtFooterName" class="tx_input_1"/>

    <a href="javascript:if(checkInfo())submitform();"><div class="button_2" >确定</div></a>
    
    

    JS文件代码:

     $(function(){
        String.prototype.enHtml = function () {
        return this.replace(new RegExp("<", "gm"), "&lt;").replace(new RegExp(">", "gm"), "&gt;");
        }
     )}
     
     
     function submitform() {
         //判断不能有特殊字符
    if (CheckStr($.trim($("#txtFooterName").val()))!="") { alert("标题不能包含“" + CheckStr($.trim($("#txtFooterName").val())) + "”号"); $("#txtFooterName").focus(); return; }
         //替换<,>
         
    else { var footname = $("#txtFooterName").val().enHtml(); $("#txtFooterName").val(footname);

    document.forms["form1"].submit(); } } //检测特性字符,包含返回特殊字符 function CheckStr(str) { var SpecialCharacters = "['\"&]"; for (var i = 0; i < SpecialCharacters.length; i++) { if (str.indexOf(SpecialCharacters.charAt(i)) != -1) { return String.fromCharCode(SpecialCharacters.charCodeAt(i)); } } return ""; }

    备注:

    String.prototype动态地给String对象增加方法,上面的String.prototype.enHtml = function () {.....}就是;
    下面是常用的方法:

    // 返回字符的长度,一个中文算2个
    String.prototype.ChineseLength=function()
    { 
        return this.replace(/[^\x00-\xff]/g,"**").length;
    }
    // 判断字符串是否以指定的字符串结束
    String.prototype.EndsWith = function(str) 
    {
        return this.substr(this.length - str.length) == str;
    }
    // 去掉字符左端的的空白字符
    String.prototype.LeftTrim = function()
    {
        return this.replace(/(^[\\s]*)/g, "");
    }
    // 去掉字符右端的空白字符
    String.prototype.RightTrim = function()
    {
        return this.replace(/([\\s]*$)/g, "");
    }
    // 判断字符串是否以指定的字符串开始
    String.prototype.StartsWith = function(str) 
    {
        return this.substr(0, str.length) == str;
    }
    // 去掉字符两端的空白字符
    String.prototype.Trim = function()
    {
        return this.replace(/(^\s*)|(\s*$)/g, "");
    }
  • 相关阅读:
    centos rm -rf 恢复删除的文件
    默认hosts后面为files dns
    linux shell expr 使用
    QQ,MSN,Skype在线客服代码
    LocalResizeIMG前端HTML5本地压缩图片上传,兼容移动设备IOS,android
    php读取和保存base64编码的图片内容
    linux shell 字符串操作(长度,查找,替换)详解
    tomcat的简单配置与适用默认的web应用
    mybatis左连接需要输出左表的指定内容与筛选
    first head in html 笔记
  • 原文地址:https://www.cnblogs.com/wxh19860528/p/2856594.html
Copyright © 2011-2022 走看看