select read-only tag set several solutions

Requirements: read-only, but need to be passed to the background.

readonly Set to select an invalid tag!

 

One embodiment, a method directly using the tag setting can not be changed js (recommended)

<select readonly="readonly" onfocus="this.defaultIndex=this.selectedIndex;" onchange="this.selectedIndex=this.defaultIndex;">

 

Second way, the first use of disabled attribute display, but the need to remove the disabled attribute before the form is submitted. Otherwise, the argument can not be delivered to the background

< SELECT ID = " PID " Readonly = "Readonly" disabled = " disabled " /> // When this method is used, removal of the disabled property before submitting the form, $ ( "# pid") removeAttr ( "disabled").;

 

Three ways to disable the clicks trigger event js

<Select id = "pid" readonly = "readonly" /> // clicks triggered when disabled

  

$(function(){
    $("#pid").click(function(){
        return false;
    });   
}

 

Four ways, the use of disabled and hidden input field to pass value (recommended)

<select readonly disabled="disabled" />

  

<INPUT name = " PID " value = " parameter value of the real need to pass " type = " hidden "  class = " hidden " >

Guess you like

Origin www.cnblogs.com/zwesy/p/12175600.html