2013年8月13日 星期二

javascript-readonly if ($(this).is('[readonly]')) {editMode='readonly';}

if ($(this).is('[readonly]')) {editMode='readonly';}



function X_readonly (v_field,v_mode){}



<%if (MODE.equals("VIEW")){%>
$('input[type="text"]').keypress(function(e){e.preventDefault();}); 
<%}%>


function _readonly (v_field,v_mode)
{
$(v_field).each(function() {
  switch(this.type) {
    case 'radio':
    case 'checkbox': if (this.checked) alert(this.value); break;
    case 'text':
     if (v_mode) {
var temp_col={'background-color': '#dcdcdc', 'color':'#000'};
this.onclick = function(event) {return false;};
$(v_field).attr('readonly',true) ;          
$(v_field).attr('onclick',function (){return false;}) ;                        
}
else
{var temp_col={'background-color': 'white', 'color':'black'};
this.readonly=false;
this.onclick = function(event) {return true;};
$(v_field).attr('readonly',false) ;                        
$(v_field).attr('onclick',function (){return true;}) ;
}
$(v_field).css(temp_col);
    break;
    case 'textarea':
     case 'hidden':
    case 'button': _disabled(v_field,v_mode); break;
    case 'select-one': alert(this.value); break;
    default: alert("unhandled type: "+this.type);
  }
});
}

沒有留言:

張貼留言