On keypress event, how do I change a ',' to a '~'

前端 未结 3 1686
无人及你
无人及你 2021-01-25 07:31

I have to prevent Coldfusion\'s default list delimiter \',\' from being entered into a form input array. I am new to using javascript for validation purposes, and have never tri

3条回答
  •  猫巷女王i
    2021-01-25 08:08

    Imho, there's no need to check those keyCodes:

     $(document).ready(function(event){
        $('#fieldName').keyup(function(event) {
            var cleanedValue = $(this).val().replace(",","~");
            $(this).val(cleanedValue);
        });
    });
    

    Check it on jsFiddle.

提交回复
热议问题