javascript 清除輸入框中的數(shù)據(jù)
更新時間:2009年04月13日 11:07:50 作者:
清楚輸入框中的數(shù)據(jù)實現(xiàn)代碼。
<li id=""><span>***</span>評論<span>鮮果</span><a href="#message_area" onclick=" fillInMessageArea(this);">回復(fù)</a></li>
<li id=""><span>pizicai</span>評論<span>you</span><a href="#message_area" onclick=" fillInMessageArea(this);">回復(fù)</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 = '回復(fù)' + 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();
}
}
<li id=""><span>pizicai</span>評論<span>you</span><a href="#message_area" onclick=" fillInMessageArea(this);">回復(fù)</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 = '回復(fù)' + 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();
}
}
相關(guān)文章
(僅IE下有效)關(guān)于checkbox 三態(tài)
(僅IE下有效)關(guān)于checkbox 三態(tài)...2007-05-05檢測郵箱地址是否合法 Check Mail Address (For: IE5+、FF1.06、Opera 7+ ...
檢測郵箱地址是否合法 Check Mail Address (For: IE5+、FF1.06、Opera 7+ ...)[...2006-12-12JS option location 頁面跳轉(zhuǎn)實現(xiàn)代碼
JS中l(wèi)ocation對象 在option中的應(yīng)用(跳轉(zhuǎn)采單),方便通過 option實現(xiàn)頁面的切換2008-12-12用javascript實現(xiàn)不按Ctrl實現(xiàn)Multiple Select多選
用javascript實現(xiàn)不按Ctrl實現(xiàn)Multiple Select多選...2007-08-08