欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

javascript 清除输入框中的数据

程序员文章站 2022-07-11 18:22:48
  • ***评论鲜果 <li id=""><span>***</span>评论<span>鲜果</span><a href="#message_area" onclick=" fillinmessagearea(this);">回复</a></li>
    <li id=""><span>pizicai</span>评论<span>you</span><a href="#message_area" onclick=" fillinmessagearea(this);">回复</a></li>
    <form action="">
    <textarea onkeyup="rewrite();" rows="4" cols="30" id="message_area" name="message_area"></textarea>
    <p></p>
    <input type="submit"/>
    <input class="not_write" id="input_rewrite" type="button" onclick="clearall();"/>
    </form>
    </div>
    <script type="text/javascript">
    function fillinmessagearea(othis){
    var text = othis.parentnode.childnodes[0].firstchild.nodevalue;
    text = '回复' + text;
    text += ':';
    var me_area = $('#message_area');
    me_area.val("");
    me_area.val(text);
    setfocus();
    }
    function clearall(){
    var me_area = $('#message_area');
    var input = document.getelementbyid('input_rewrite');
    if(me_area.attr('class') == 'not_write') return false;
    var text = me_area.val();
    text= text.replace(/(^\s+(:)+?)(\s*.+\s*)+/,"$1");
    if(!text.match(/(.*?):/))
    me_area.val("");
    else
    me_area.val(text);
    setfocus();
    hide_rewrite(input);
    }
    function rewrite(){
    var me_area = $('#message_area');
    var text = me_area.val();
    var input = document.getelementbyid('input_rewrite');
    if(text.match(/^\s+(:)+?(\s*.+\s*)+/) ||(!text.match(/(.*?):/)))
    show_rewrite(input);
    //input.value= "not null";
    else
    hide_rewrite(input);
    if(text=='')
    hide_rewrite(input);
    //input.value = "null";
    //alert('null');
    }
    function show_rewrite(input){
    input.classname = "can_rewrite";
    }
    function hide_rewrite(input){
    input.classname = "not_write";
    }
    function setfocus(){
    esrc = document.getelementbyid('message_area');
    //esrc.focus();
    var rtextrange = "";
    if(esrc.createtextrange){
    rtextrange = esrc.createtextrange();
    rtextrange.movestart('character',esrc.value.length);
    rtextrange.collapse(true);
    rtextrange.select();
    }
    }