How to test if the browser supports the native placeholder attribute?

后端 未结 4 489
囚心锁ツ
囚心锁ツ 2020-12-13 04:35

I\'m trying to write a simple placeholder jQuery plugin for a site of mine but of course I only want to fire the function if the native placeholder attribute isn\'t supporte

4条回答
  •  北海茫月
    2020-12-13 04:45

    Use the Modernizr library, which you can find here: http://www.modernizr.com/

    And then do this:

    if (Modernizr.input.placeholder) {
      // your placeholder text should already be visible!
    } else {
      // no placeholder support :(
      // fall back to a scripted solution
    }
    

    Modernizr is really handy for testing the browser's support for almost all HTML5 functionality.

提交回复
热议问题