用onkeyup事件应该可以吧
触发,判断,替换

解决方案 »

  1.   

    $htmlStr = htmlspecialchars("<");
    echo $htmlStr;
      

  2.   

    function HtmlEncode(text)
    {
        return text.replace(/&/g, '&amp').replace(/\"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
    }
      

  3.   

    这是替换,我需要是的当按下“<”键时,便出现“&lt”字符.
      

  4.   

    <script language="JavaScript">
    <!--
    var isShiftDown=false;
    function dealKeyDown(src){
    txtShow.value=window.event.keyCode;
    if(window.event.keyCode==16){
    isShiftDown=true;
    return ;
    }
    if(window.event.keyCode==188 && isShiftDown){
    window.event.returnValue=false;
    src.value+="&lt;";
    return false;
    }
    }
    function keyup(){
    isShiftDown=false;
    }
    //-->
    </script>
    <input type="text" id="txtInput" size=20 onkeydown="dealKeyDown(this)" onKeyUp="keyup()">
    <input type="text" id="txtShow" size=20 readonly>