javascript 清除輸入框中的數(shù)據(jù)
更新時(shí)間:2009年04月13日 11:07:50 作者:
清楚輸入框中的數(shù)據(jù)實(shí)現(xiàn)代碼。
<li id=""><span>***</span>評(píng)論<span>鮮果</span><a href="#message_area" onclick=" fillInMessageArea(this);">回復(fù)</a></li>
<li id=""><span>pizicai</span>評(píng)論<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>評(píng)論<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)文章
js驗(yàn)證符合用戶體驗(yàn)的網(wǎng)頁(yè)表單特效
用CSS和JS設(shè)計(jì)的符合用戶體驗(yàn)的表單。大家可以在自己的網(wǎng)頁(yè)里面用用,自己感覺非常不錯(cuò)的一種效果。2008-10-10
javascript獲得光標(biāo)所在的文本框(text/textarea)中的位置
移動(dòng)鼠標(biāo),得到單元格所在表中的位置的js代碼,測(cè)試兼容firefox,需要的朋友可以參考下。2009-12-12
js限制文本框?yàn)檎麛?shù)和貨幣的函數(shù)代碼
js限制文本框?yàn)檎麛?shù)和貨幣的函數(shù)代碼,方便一些數(shù)據(jù)庫(kù)字段的控制。2010-10-10
Javascript 文本框textarea高度隨內(nèi)容自適應(yīng)增長(zhǎng)收縮
之前一段時(shí)間項(xiàng)目中用到的一個(gè)功能,用Javascript控制文本框textarea高度隨內(nèi)容自適應(yīng)增長(zhǎng)收縮,今天花了點(diǎn)時(shí)間換了種實(shí)現(xiàn)方法,總結(jié)一下。2011-07-07
用javascript實(shí)現(xiàn)文本框和"選擇"按扭之間的間距
用javascript實(shí)現(xiàn)文本框和"選擇"按扭之間的間距...2007-07-07

