How I can add and remove the attribute “readonly”?

前端 未结 4 1285
灰色年华
灰色年华 2021-02-18 20:19
$(document).ready(function() {
  //Check City Value
  var city_value = parseInt($(\"#city\").val());
  if( city_value == 0) {
     $(\"#state\").attr(\"readonly\", true)         


        
4条回答
  •  终归单人心
    2021-02-18 21:04

    Works fine here in all major browsers I have. Here's an SSCCE:

    
    
        
            SO question 2496443
            
            
            
        
        
            
            
        
    
    

    Toggling it turns the background gray (although not all browsers do that) and the input is uneditable (this is consistent among all webbrowsers). So your problem lies somewhere else. You're probably using a poor doctype and possibly also in combination with a poor webbrowser.

提交回复
热议问题