Can I specify maxlength in css?

前端 未结 8 397
情歌与酒
情歌与酒 2020-12-03 16:45

Can I replace the maxlength attribute with something in CSS?


相关标签:
8条回答
  • 2020-12-03 17:04

    I don't think you can, and CSS is supposed to describe how the page looks not what it does, so even if you could, it's not really how you should be using it.

    Perhaps you should think about using JQuery to apply common functionality to your form components?

    0 讨论(0)
  • 2020-12-03 17:07

    No. This needs to be done in the HTML. You could set the value with Javascript if you need to though.

    0 讨论(0)
  • 2020-12-03 17:08

    Use $("input").attr("maxlength", 4) if you're using jQuery version < 1.6 and $("input").prop("maxLength", 4) if you are using jQuery version 1.6+.

    0 讨论(0)
  • 2020-12-03 17:14

    Not with CSS, no.

    0 讨论(0)
  • 2020-12-03 17:18

    Not with CSS, but you can emulate and extend / customize the desired behavior with JavaScript.

    0 讨论(0)
  • 2020-12-03 17:20

    You can use jQuery like:

    $("input").attr("maxlength", 4)
    

    Here is a demo: http://jsfiddle.net/TmsXG/13/

    0 讨论(0)
提交回复
热议问题