0

So i have this page: http://www.prxa.info/index.php?module=articles&view=Submit

Using jquery and code i am trying found here: https://stackoverflow.com/a/13516186/1741251

I am trying to do a twitter like character count for the first textarea counting down from 255 but it doesn't seem to work for me?

I have basically no experience with javascript :(

This is the code I am using to count it:

<script type="text/javascript">
$(document).ready(function () {
    $('#tagline').keypress(function (event) {
        var max = 255;
        var len = $(this).val().length;
        if (event.which < 0x20) {
            // e.which < 0x20, then it's not a printable character
            // e.which === 0 - Not a character
            return;     // Do nothing
        }
        if (len >= max) {
            event.preventDefault();           
        }            

    });
    $('#tagline').keyup(function (event) {
        var max = 250;
        var len = $(this).val().length;       
        var char = max - len;
        $('#textleft').text(char + ' characters left');

     });

4

1 回答 1

0

像这样的东西

$('#inputBox').keyup(function (event) {
    var len = $(this).val().length;
    $('#holder').text(len );
});
于 2012-12-03T11:48:07.840 回答