简体   繁体   中英

onclick/onSubmit events on iOS

I have the below html which is a form submit that I used preventDefault to stop refreshing on submit.

All was good so far but the submit button wouldn't work on IOS. (onsubmit event simply wouldnt fire)

I've given a try to every single related post and suggestions within such as swapping to an actual button with onClick event, every other kind of touchStart or onTouch event, cursor: pointer css trick and registering listener with jquery on page ready or load, however none of seemed to get me to use the button on iOS.

Everything including the submit button works fine in any other platform than iOS.

<form id = "altB">  
    <input type = "text" name = "altName" id = "altName" placeholder = "Name">
    <input type = "text" name = "altRealm" id = "altRealm" placeholder = "Realm"><br><br>
    <input class = "altButton buttonAnim" id = "tempid" type="submit" value="Add alt"><br>
</form>
<script> document.getElementById('altB').addEventListener('submit', function(event){event.preventDefault();temp();});
</script>

For iOS, include "touchstart" like below,

$('#altB').on('click touchstart', function() {
    ---Your logic
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM