Yazar Mesaj
Kaan #74   2019-11-21 09:14 GMT        

Yönetici

Çevrimiçi durum

76 mesajları
https://ntka.org

Karakter Sayımı

textareaMaxCharacters( $('textarea.maxCharacters'),200, $('span.maxCharacters'));

function textareaMaxCharacters(obj, maxCharacters, countText)
{
    obj.on('keydown keyup keypress change',function ()
    {
        if( $( this ).val().length >= maxCharacters )
        {
            $( this ).val( $( this ).val().substr(0,maxCharacters));
        } 
        countText.html( $( this ).val().length + ' Characters');
    });
}

Kullanımı


 <textarea class='maxCharacters'></textarea>
                <span class='maxCharacters'></span>

Kelime Sayımı

textareaMaxKeywords($('textarea.maxKeywords'),10,$('span.maxKeywords'));

function textareaMaxKeywords(obj, maxKeywords, countText)
{
    obj.on('keydown keyup keypress change',function ()
    {
        if( $.trim( $( this ).val() ).split(' ').length >= maxKeywords )
        {
            $( this ).val( $( this ).val().split(' ').slice(0, maxKeywords).join( ' ' ) );
        } 
        countText.html( $( this ).val().split( ' ' ).length + ' keywords');
    });
}

Kullanımı

<textarea class='maxKeywords'></textarea>
                <span class='maxKeywords'></span>

Javascript ilave etmeden çalışmaz

 <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>  

Kaynak Kodları

 <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="tr">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
            <title>textarea max characters and  keywords </title>
            <style type="text/css">
                .col{width: 50%; float: left;}
                textarea{height: 160px;}
            </style>
        </head>
        <body>
            <div class='col'>
                <h1>Max Characters</h1>
                <p>
                    textareaChar( $( 'textarea.maxCharacters' ), 200, $( 'span.maxCharacters' ) );
                </p>
                <textarea class='maxCharacters'></textarea>
                <span class='maxCharacters'></span>
            </div>
            <div class='col'>
                <h1>Max Keywords</h1>
                <p>
                    textareaMaxKeywords( $( 'textarea.maxKeywords' ), 10 ,$( 'span.maxKeywords' ) );
                </p>
                <textarea class='maxKeywords'></textarea>
                <span class='maxKeywords'></span>
            </div>
            <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>      
            <script type="text/javascript">

                textareaMaxCharacters( $('textarea.maxCharacters'),200, $('span.maxCharacters'));

                textareaMaxKeywords($('textarea.maxKeywords'),10,$('span.maxKeywords'));

                function textareaMaxCharacters(obj, maxCharacters, countText)
                {
                    obj.on('keydown keyup keypress change',function ()
                    {
                        if( $( this ).val().length >= maxCharacters )
                        {
                            $( this ).val( $( this ).val().substr(0,maxCharacters));
                        } 
                        countText.html( $( this ).val().length + ' Characters');
                    });
                }

                function textareaMaxKeywords(obj, maxKeywords, countText)
                {
                    obj.on('keydown keyup keypress change',function ()
                    {
                        if( $.trim( $( this ).val() ).split(' ').length >= maxKeywords )
                        {
                            $( this ).val( $( this ).val().split(' ').slice(0, maxKeywords).join( ' ' ) );
                        } 
                        countText.html( $.trim($( this ).val() ).split( ' ' ).length + ' keywords');
                    });
                }

            </script>
        </body>
    </html>