Html-ios a solution that does not add a style to the input below

Source: Internet
Author: User

Problem Description:

1 <!DOCTYPE HTML>2 3 <HTMLLang= "en"xmlns= "http://www.w3.org/1999/xhtml">4 <Head>5     <MetaCharSet= "Utf-8" />6     <title></title>7     <style>8 input{width:100px;Height:25px;Background-color:#ff6a00;Outline:None;}9 input:active{Background-color:#00ff21;Transform:Translate (2px,2px);-webkit-transform:Translate (2px,2px); /*Google*/-moz-transform:Translate (2px,2px); /*Safari*/-webkit-transform:Translate (2px,2px); /*op*/}Ten     </style> One </Head> A <Body> -     <inputtype= "button"value= "Refresh" /> - </Body> the </HTML>

The problem code above, input CSS style add invalidation

(Touch-style active style add also fails)

Reason:

1, iOS default to input style added, our style is overwritten

2, iOS input manually need to activate the active state, otherwise active will not work

Workaround:

1, CSS to input add:-webkit-appearance:none; "This is to remove the iOS default input style"

2. Manually activate the active state to bind the Touchstart event to the body/html or element:

JS native notation

1 document.body.addEventListener ("Touchstart", function () {//null function can });

JQ notation

1 $ (' body '). On ("Touchstart",function() {///null function});

Of course, sometimes, this is not enough to solve the problem, you still need to write

1 $ (function () { $ (' input '). On ("Touchstart", function () {// Empty function can});  });

Wait until the page is loaded, when the activation binding event is executed, and often you have to add on input to be effective, for what reason I have not studied clearly.

Correct wording:

1 <!DOCTYPE HTML>2 3 <HTMLLang= "en"xmlns= "http://www.w3.org/1999/xhtml">4 <Head>5     <MetaCharSet= "Utf-8" />6     <title></title>7     <style>8 input{width:100px;Height:25px;Background-color:#ff6a00;Outline:None;-webkit-appearance:None; }9 input:active{Background-color:#00ff21;Transform:Translate (2px,2px);-webkit-transform:Translate (2px,2px); /*Google*/-moz-transform:Translate (2px,2px); /*Safari*/-webkit-transform:Translate (2px,2px); /*op*/}Ten     </style> One </Head> A <Body> -     <inputtype= "button"value= "Refresh" /> -     <Script> the Document.body.addEventListener ("Touchstart", function () { -  -         }); -  +         //or -         $('input'). On ("Touchstart", function () { }); +  A  at  -         //or -         $(function () { -             $('input'). On ("Touchstart", function () { }); -         }); -  in  -     </Script> to </Body> + </HTML>

Html-ios a solution that does not add a style to the input below

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.