Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery Mobile Forms

jQuery Mobile Forms


jQuery Mobile automatically adds styles to HTML forms, making them more attractive and friendlier to touch.



jQuery Mobile Form Structure

jQuery Mobile uses CSS to add styles to HTML form elements, making them more attractive and easier to use.

In jQuery Mobile, you can use the following form controls:

When using jQuery Mobile forms, you should know:

Example

method="post" action="demoform.html"

id="fname"

Try it »

To hide a label, use the class ui-hidden-accessible. This is often used when you use an element's placeholder attribute as a label:

Example

class="ui-hidden-accessible"

Name:

Try it »

Tip: We can use the data-clear-btn="true" attribute to add a button that clears the input field (an X icon on the right side of the input field):

Example

data-clear-btn="true"

Try it »

Note The button to clear the input field can be used in elements, but not in

 

class="ui-field-contain"

   

   

   

   

 

Try it »

lamp The ui-field-contain class adds styles to labels and form controls based on the page width. When the page width is greater than 480px, it automatically places the label on the same line as the form control. When the page width is less than 480px, the label is placed above the form element.

**Tip:** To prevent jQuery Mobile from automatically adding styles to clickable elements, use the data-role="none" attribute:

Example

data-role="none"

Try it »

| lamp | Form submission in jQuery Mobile

 jQuery Mobile 通过 AJAX 自动处理表单提交,并将试图集成服务器响应到应用程序的 DOM 中。 |

| --- | --- |