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