JQuery settings checkbox Select Radio as Read only

Source: Internet
Author: User

The JQuery settings checkbox Select Radio is read-only, and by testing the text and textarea that use HTML tags, the button can set the readonly= "ReadOnly" property.

However, the checkbox, select, radio three controls cannot be used with the readonly= "ReadOnly" property, only disabled= "disabled" can be used.

So there's a problem. Also want to not let the changes, and want to get the value in the background. If you use the Disabled property, but you find (string value = request.form["XX"];) value is empty.

Do not want to modify the background code, and finally in the discussion with Bogo, finally came up with the following method.

[HTML]View Plaincopyprint?
  1. <%@ page language="C #" autoeventwireup="true" codefile="Default.aspx.cs" inherits= "_default"%>
  2. <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
  3. <HTML xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="Server">
  5. <title></title>
  6. <script src="scripts/jquery-1.4.1.min.js" type="Text/javascript"> </Script>
  7. <script type="Text/javascript">
  8. function Setscr_readonly () {
  9. var items = $ ("input[type=' checkbox ']")
  10. var html = ""
  11. for (var i = 0; I < items.length; i++) {
  12. Items[i]. Disabled = true;
  13. HTML + = "<input type=' text ' name='" + items[i].id + "' value='" + items[i].value + "' > ";
  14. }
  15. var items = $ ("select");
  16. for (var i = 0; I < items.length; i++) {
  17. HTML + = "<input type=' text ' name='" + items[i].id + "' value='" + Items[i].value + "'  > ";
  18. Items[i]. Disabled = true;
  19. }
  20. var items = $ (": Radio");
  21. for (var i = 0; I < items.length; i++) {
  22. HTML + = "<input type=' text ' name='" + items[i].id + "' value='" + items[i].value + "' > ";
  23. Items[i]. Disabled = true;
  24. }
  25. $ ("#divhtml"). HTML (HTML);
  26. }
  27. </Script>
  28. </head>
  29. <body>
  30. <form id="Form1" runat="Server">
  31. <div>
  32. <input type="text" readonly="readonly" />
  33.         <input   type= "button"  value=< Span class= "Attribute-value" > "not available"  onclick= "Setscr_ ReadOnly () " />  
  34. <input type="checkbox" id="R" checked="checked" runat="Server " value="Cbovalue" />
  35. <Select id="sel" name="sel">
  36. <option value="Please select"> select </option>
  37. <option value="1">1</option>
  38. </Select>
  39. <Select id= "Select1" name="Select1">
  40. <option value="Please select"> select </option>
  41. <option value="1" selected="selected">1</option>
  42. </Select>
  43.         <input   id= "RDO"  name= "RDO"  type= "Radio"  < span class= "attribute" >value= "1"  checked= "checked"  />  
  44. <Asp:button runat="Server" text="button" onclick="Unnamed1_click" />
  45. <div style="Display:none" id="divhtml">
  46. </div>
  47. </div>
  48. </form>
  49. </body>
  50. </html>
<%@ page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_default"%><! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.