2013-08-28 35 views
0

最後一個輸入(被點擊)應該只讀 - > true再次。如果點擊其他內容 - 如果點擊其他內容,則更改prop/jQuery

這裏是我的代碼:

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

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

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

    }); 
</script> 

的感謝!

+0

呃....你已經問同樣的或它的我:http://stackoverflow.com/questions/18485231/ jquery-input-prob-disable-false-by-clicking-the-input – Alvaro

+0

@Alvaro no - 現在我需要幫助點擊輸入字段後點擊其他地方 – Mike

回答

1

試試這個

--to make input editable on click 
    $('input').bind('click', function() { 
     $(this).prop("readonly", false); 
    }); 

--to make input readonly on lost focus 
    $('input').bind('blur', function() { 
     $(this).prop("readonly", true); 
    }); 
+0

偉大的工作 - 謝謝 - 但仍然沒有在iOS上工作[鏈接](http://stackoverflow.com/questions/18486676/jQuery的代碼呢 -​​ 不工作的,IOS) – Mike

0
$("input").click(function() { 
    var $that = $(this); 
    $("input").each(function() { 
     if ($(this) !== $that) { 
      $(this).prop("readonly", false); 
     } 
    });  
}); 
0

嘗試

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