jquery 기반 inputlimiter 글자 수 제한 기능 구현

효과 그림 보기:소스 코드:
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Input Limiter Demo</title>
<link rel="stylesheet" type="text/css" href="jquery.inputlimiter.1.0.css" />
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="jquery.inputlimiter.1.2.js"></script>
<style type="text/css">
body {
font-family: verdana;
}
#limitingtext {
color: #333;
font-size: 90%;
}
</style>
<script type="text/javascript">
function create_xmlDoc(){
var xmlDoc = null;
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc=document.implementation.createDocument("","",null);
}
catch(e)
{
alert(e.message);
return;
}
}
return xmlDoc;
}

$(document).ready(function() {
var xmlDoc = create_xmlDoc();
xmlDoc.async=false;
xmlDoc.load("test.xml");
var x=xmlDoc.getElementsByTagName("channel");
for( var i=0; i<x.length; i++ ){
if(x[i].getAttribute("CID") == '1'){
num = x[i].childNodes[0].getAttribute("fNum");
strfield = x[i].childNodes[0].getAttribute("FID");
//
$("#"+strfield).inputlimiter({
limit: num,
remText: ' %n ',
remFullText: ' ',
limitText: ''
});
//$("#hidNum").val(num);
}
}

$("#SendLimiter").click(function(){
if($("#Num").val().length==0){
alert(" !");
return;
}
if(isdigit($("#Num").val())==0){
alert(" !");
return;
}
$.ajax({
url:'SaveLimiter.asp', //
type:'Post', //
data:"Num=" + $("#Num").val() + "&ChannelID=1"+"&Field="+$("#sel").val(), //
success:update_page, // ( )
error:errorInfo
});
});

// , XMLhttpRequest.responseText
function update_page (data) {
//alert(data);
alert(" !");
}

function errorInfo(data){
alert(" !"+data.responseText);
}

//
function isdigit(s){
var r,re;
re = /\d*/i; //\d ,*
r = s.match(re);
return (r==s)?1:0;
}
});
</script>
</head>
<body>
<h1> </h1>
<form >
<fieldset>
<legend> </legend>
:<input type="text" id="TITLE" size="50" style="border: 1px solid gray"/><br />
1:<input type="text" id="ceshi1" size="50" style="border: 1px solid gray"/><br />
2:<input type="text" id="ceshi2" size="50" style="border: 1px solid gray"/><br />
</label><br /><br />
<label> :
<select id="sel">
<option value="TITLE"> </option>
<option value="ceshi1"> 1</option>
<option value="ceshi2"> 2</option>
</select>
<input type="text" class="cmsField" style="width:80px" id="Num"><input type="button" value=" " id="SendLimiter">
</fieldset>

</form>
</body>
</html>
이 곳 의 제한 글자 수 는 동적 으로 설정 되 어 있 기 때문에 ASP 페이지 와 XML 파일 ASP
 
<%
num = Trim(Request("Num")) '
channelid = Trim(Request("ChannelID")) ' ID
sfield = Trim(Request("Field")) '

set objDom = server.CreateObject("MicroSoft.XMLDom")
objDom.load(Server.MapPath("test.xml"))
Set objNode = objDom.documentElement
'
newint=objNode.ChildNodes.length-1
for i=0 To newint
' id
set objarr=objNode.ChildNodes.item(i)
if ( objarr.Attributes.item(1).Text = channelid) then
if( objarr.ChildNodes.item(0).Attributes.item(1).Text = sfield ) then
' ID
objDom.getElementsByTagName("channel").item(i).childNodes.item(0).Attributes.item(2).Text = num
exit for
end if
end if
set objarr = Nothing
next
objDom.save(Server.MapPath("test.xml"))
set objNode = Nothing
Set objDom = Nothing
%>
XML
 
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TurboCMSXML>
<channel cName=" 1" CID="1">
<Field fName=" " FID="TITLE" fNum="20"/>
</channel>
<channel cName=" 1" CID="1">
<Field fName=" 1" FID="ceshi1" fNum="20"/>
</channel>
<channel cName=" 1" CID="1">
<Field fName=" 2" FID="ceshi2" fNum="200"/>
</channel>
<channel cName=" 2" CID="2">
<Field fName=" 2" FID="ceshi2" fNum="20"/>
</channel>
<channel cName=" 3" CID="3">
<Field fName=" 3" FID="ceshi3" fNum="10"/>
</channel>
<channel cName=" 4" CID="4">
<Field fName=" 4" FID="ceshi4" fNum="20"/>
</channel>
</TurboCMSXML>
을 설정 하 였 습 니 다.

좋은 웹페이지 즐겨찾기