欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

FCKEidtor 自動(dòng)統(tǒng)計(jì)輸入字符個(gè)數(shù)(IE)

 更新時(shí)間:2009年05月29日 20:43:16   作者:  
由于項(xiàng)目需要,需要做字?jǐn)?shù)統(tǒng)計(jì),于是寫(xiě)了一個(gè)JS計(jì)算字符個(gè)數(shù),如果輸入的字符數(shù)大于100個(gè)字符,就彈出提示,點(diǎn)擊【確定】后,自動(dòng)截取為100個(gè)字符。
此方法支持IE 不支持火狐??赡苁且?yàn)镕CKEidtor的keyup方法在火狐下不被支持。
FCKEditor編輯器換為T(mén)extBox,應(yīng)該就沒(méi)有問(wèn)題了。
前臺(tái):
復(fù)制代碼 代碼如下:

<tr>
<th>
短敘述
<br />
(限100中文字)<br />
當(dāng)前文字個(gè)數(shù):<asp:Label ID="lblShowTextLength" runat="server" Text="0" ForeColor="Red"></asp:Label><br />
</th>
<td style="text-align: left;">
<FCKeditorV2:FCKeditor ID="fckPrdDescription" runat="server" Height="240px" Width="100%">
</FCKeditorV2:FCKeditor>
</td>
</tr>

JS代碼:
復(fù)制代碼 代碼如下:

<script type="text/javascript">
function FCKeditor_OnComplete(editorInstance)
{
var oEditor = FCKeditorAPI.GetInstance('fckPrdDescription');
oEditor.EditorDocument.body.onkeyup=function ()
{
if( document.all)
{
$("lblShowTextLength").innerText =oEditor.EditorDocument.body.innerText.length;
}
else
{
var r = oEditor.EditorDocument.createRange() ;
r.selectNodeContents( oEditor.EditorDocument.body ) ;
$("lblShowTextLength").innerText= r.toString().length ;

}
if(parseInt($("lblShowTextLength").innerText)>100)
{
alert("當(dāng)前已經(jīng)達(dá)到100中文字,請(qǐng)不要繼續(xù)輸入!");
oEditor.EditorDocument.body.innerText=oEditor.EditorDocument.body.innerText.substring(0,100);
$("lblShowTextLength").innerText =oEditor.EditorDocument.body.innerText.length;
}
// $("ddd").value =oEditor.EditorDocument.body.innerHTML;
}
if (document.getElementById("hidStatus").value=="Cancel")
{
editorInstance.EditorDocument.designMode="off";
}
}
</script>

演示:
輸入多馀100個(gè)字符數(shù) 提示

點(diǎn)擊【確定】后 自動(dòng)截取100個(gè)字符

相關(guān)文章

最新評(píng)論