Fix a character to text input box using javascript/jquery

后端 未结 5 1842
离开以前
离开以前 2020-12-08 11:24

I am looking for a way to \'fix\' a dollar symbol $ to a text input box eg but make it not possible for the default va

5条回答
  •  旧时难觅i
    2020-12-08 11:56

    Expanding on Pekka's answer, I used this on my page, but I automated it a little bit with jQuery. So for this example, all of the input fields that I want to put a $ symbol in, I give them a class of "cost".

    CSS:

    
    

    jQuery:

    
    

    This will place the span with a class of "cost" right before your input, and also wrap a div around both the input, and the span, so they are ensured to be on the same line.

    If you don't have jQuery, you can get it from: jQuery.com

    Now I've got a quick question - I noticed that with this styling, in IE6,7, and 8, the $ symbol is not lined up correctly. Does anybody out there have a fix for this?

    Thank you!

提交回复
热议问题