jquery Easyui grid table special character processing

Source: Internet
Author: User

Grid gets data, if the data exists test characters, or JS statement, will cause the page layout confusion, the following method, so that the obtained data all as text to display

This action mainly prevents the following highlights

1. Due to business needs, there are special characters or JS statements in the data of the query, such as: "Alert (' Product Code '), the field in the database field,", then the fields are found in the table, the page will pop up a prompt box

The field of the 2.grid query comes from the text entered manually by the user, and if there is a malicious attack, the input JS statement will execute the relevant statement.

Call HTMLEncode when the table field formatter

{field: ' Dladdress ', title: ' Place of Use ', Width:200,align: ' Center ',

Formatter:function (value, row, index) {
return HTMLEncode (value);
}
}

/*-----------------------------------------------------------------------------------------*\
* Function: Convert special characters
* Parameters: Value--a string that needs to be converted
* Return value:
Description
\*-----------------------------------------------------------------------------------------*/
function HTMLEncode (value) {
var returnvalue;
if (value==null) {
return null;
}
returnvalue = Value.replace (/&/g, ' & ');
returnvalue = Returnvalue.replace (/</g, ' &lt; ');
returnvalue = Returnvalue.replace (/>/g, ' &gt; ');

returnvalue = Returnvalue.replace (/\n\n/g, ' <br/> ');
returnvalue = Returnvalue.replace (/\r\r/g, ' <br/> ');
returnvalue = Returnvalue.replace (/\n/g, ' <br/> ');
returnvalue = Returnvalue.replace (/\r/g, ' <br/> ');
returnvalue = Returnvalue.replace (/\t/g, ' &nbsp; ');
Return returnvalue;
}

jquery Easyui grid table special character processing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.