jQuery code does not work on iOS

2019-08-02 20:56发布

问题:

this code is working fine on desktop browsers, but on iOS (iPhone 5 / iOS 7) it doesn't. By clicking outside the clicked input, the clicked input does not get readonly->true again. UPDATED CODE:

    <script>
    $(document).ready(function () {

    $("input").prop("readonly", true);

    $('input').bind('click', function () {
        $(this).prop("readonly", false);
    });

    $('input').bind('blur', function () {
        $(this).prop("readonly", true);  
    });

    });
    </script>

回答1:

Use this for adding readonly attribute,

To add,

$("input").attr("readonly", "readonly");

To remove,

$("input").removeAttr("readonly");

This is the correct method



标签: jquery ios click