8587a342cadc6ad12c90724185b50a302e7e99fd.svn-base 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*******************************************************************************
  2. * ������ encode(word) ���ܣ� ����HTML ��ڲ��� word ����ֵ��
  3. * ��html��ʽ�����ύ��html�ı�
  4. ******************************************************************************/
  5. function encode(word) {
  6. illegalchar = new Array('<', '&', '"', ">", ' ');
  7. var result = "", result1 = "", temp = "";
  8. for (var j = 0; j < illegalchar.length; j++) {
  9. // if (word.indexOf(illegalchar[j])!=-1){
  10. // for(int i=0;i<word.length;i++)
  11. while (word.indexOf(illegalchar[j]) != -1) {
  12. var k = word.indexOf(illegalchar[j])
  13. resultFirst = word.substring(0, k)
  14. // document.write("ww"+k)
  15. var c = word.charAt(k)
  16. switch (c) {
  17. case '<' :
  18. temp = "&lt;";
  19. break;
  20. case '&' :
  21. temp = "��";
  22. break;
  23. case '>' :
  24. temp = "&gt;";
  25. break;
  26. case '"' :
  27. temp = "&quot;";
  28. break;
  29. case ' ' :
  30. temp = "&nbsp;";
  31. break;
  32. // default : continue;
  33. }
  34. result = result + resultFirst + temp
  35. word = word.substring(k + 1, word.length)
  36. // document.write(result+"0"+temp+"0"+word.substring(0,k))
  37. // result=result+temp+word.substring(0,k)
  38. // word=word.substring(k+1,word.length)
  39. // document.write(u)
  40. // document.write(word+u)
  41. // document.write(word)
  42. }
  43. // result=result+word
  44. // document.write(word)
  45. // result=result+word.substring(0,k)
  46. }
  47. // document.write("www"+word)
  48. result = result + word
  49. // document.write(result)
  50. if (result.length == 0)
  51. return word;
  52. // document.write(result)
  53. return result;
  54. }