欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
Checkbox的checked屬性問(wèn)題

轉自:http://www.cnblogs.com/net205/archive/2008/08/31/1280432.html

 

  前幾天開(kāi)發(fā)中用Javascript腳本創(chuàng )建Checkbox時(shí),發(fā)現設置checked屬性有問(wèn)題,后來(lái)測試得到設置checked屬性在IE,Firefox,Opera中存在差異。

 

   我們先來(lái)看一下網(wǎng)上搜索到的例子。

  1、Internet Explorer 6 and the checked checkbox

   http://claudio.cicali.org/article/90/ie-6-and-the-checked-checkbox  

   You dinamically create a checkbox and then put its state to checked. Then, you append your new checkbox to its parent. In firefox there’s nothing wrong with that. But Internet Explorer DOES NOT check the box. Why? Well, FIRST you have to show the checkbox and THEN check it.

 

So: 

Html代碼
  1. chk = document.createElement('INPUT')  
  2. chk.type='checkbox'  
  3. chk.checked=true  
  4. document.getElementById('container').appendChild(chk)  

 Does not work in IE. You have to rewrite this as:

Html代碼
  1. chk = document.createElement('INPUT')  
  2. chk.type='checkbox'  
  3. document.getElementById('container').appendChild(chk)  
  4. chk.checked=true  

 

從這里我們可以看出在IE中,checked屬性需要在添加到頁(yè)面以后設置才有效,而FF,Opera都不存在此現象。

 

  2、firefox和ie下面的初始化checkbox
http://www.cnblogs.com/sxlfybb/archive/2008/03/20/1114242.html

 

   這篇日志得出同樣的結果。(申明:firefox下是支持cb.checked=true這樣的寫(xiě)法,checked是一個(gè)可讀寫(xiě)的屬性。至少我的環(huán)境是正常的。)

 

  3、使用CheckBox的indeterminate屬性的問(wèn)題

   http://blog.csdn.net/yangdengfeng2003/archive/2007/05/05/1597399.aspx  

 

   這篇日志提到了CheckBox的indeterminate屬性的問(wèn)題,注意:CheckBox的indeterminate是一個(gè)獨立的 屬性,和CheckBox的checked、status的取值無(wú)關(guān),也就是說(shuō)它只會(huì )影響CheckBox的外觀(guān)顯示,我們仍然可以正常的使用腳本讀取 checked和status的值。

 

   4、DOM & checkbox(checked status)

   http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=842144&SiteID=1

 

        帖子中提到Checkbox在IE6和IE7下的多種情況。(此帖子中的代碼本人沒(méi)有測試過(guò)。)

 

   最后看看本人測試結果及結論:

 

Html代碼
  1.  1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2.  2 <html xmlns="http://www.w3.org/1999/xhtml">  
  3.  3  <head>  
  4.  4   <title>CheckBox Example</title>  
  5.  5   <meta name="generator" content="editplus" />  
  6.  6   <meta name="author" content="Net205" />  
  7.  7   <meta name="keywords" content="Net205,冷風(fēng)工作室" />  
  8.  8   <meta name="description" content="CheckBox Example in IE、FF、OP" />  
  9.  9   <meta http-equiv='Cache-Control' content='no-cache'/>  
  10. 10  </head>  
  11. 11   
  12. 12 <body>  
  13. 13 <%  
  14. 14     Response.Buffer = true  
  15. 15     Response.Expires = 0  
  16. 16     Response.ExpiresAbsolute = Now() - 1       
  17. 17     Response.CacheControl = "no-cache"    
  18. 18     Response.AddHeader "Pragma", "No-Cache"   
  19. 19   
  20. 20     For Each e In Request.Form  
  21. 21         Response.Write e & " : " & Request.Form(e) & "<br />"  
  22. 22     Next  
  23. 23   
  24. 24 %>  
  25. 25 <form id="frm" name="frm" method="post" action="?">  
  26. 26     <input type="checkbox" id="chkTest1" name="chkTest1" value="1" />  
  27. 27     <script>  
  28. 28         /*you can use setAttribute to set the value of attribute,like this:  
  29. 29           chk.setAttribute("name", "chkTest2"),chk.setAttribute("checked", true)*/  
  30. 30         var chk1 = document.createElement('input');  
  31. 31         chk1.id = "chkTest2";  
  32. 32         chk1.name = "chkTest2";  
  33. 33         chk1.type = "checkbox";  
  34. 34         chk1.value = "1";  
  35. 35         //chk1.defaultChecked=true;  
  36. 36         //chk1.indeterminate = true;  
  37. 37         document.getElementById('frm').appendChild(chk1);  
  38. 38         chk1.checked=true;  
  39. 39     </script>  
  40. 40     <input type="submit" />  
  41. 41 </form>  
  42. 42 </body>  
  43. 43 </html>  
 

 

   結論:
1、當用Javascript腳本創(chuàng )建并添加CheckBox復選框時(shí),對于IE,必須在添加(如:appendChild)后設置checked值才有效,FF、OP都有效,無(wú)此現象。
2、defaultChecked直接寫(xiě)到屬性里,IE、FF、OP都不支持,當用Javascript腳本設置為true時(shí),都支持(無(wú)順序關(guān)系),并在服務(wù)器端可以取到值。
3、indeterminate當屬性添加時(shí)IE、FF、OP都無(wú)效,只有當用Javascript腳本設置時(shí),IE才有效,并在服務(wù)器端取不到值,只會(huì )影響CheckBox的外觀(guān)顯示。
4、當用setAttribute設置checked值時(shí),如果為unchecked狀態(tài),對于FF、OP則不需要設置任何值,就算設置為fasle、"false"或""(空字符串),checkbox都為選中狀態(tài)。

   5、類(lèi)似document.createElement("<input type=checkbox>");創(chuàng )建元素時(shí),只有IE才有效。


說(shuō)明:本人測試環(huán)境為IE6.0 sp2、Firefox 3.0.1、Opera 9.52,如有其他情況,請各位同仁指出。

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
免費設置個(gè)人形象
jquery js radio單選框取值和賦值
jquery中attr和prop的區別分析
jQuery獲取attr()與prop()屬性值的方法及區別介紹
jQuery操作復選框checkbox技巧總結 ---- 設置選中、取消選中、獲取被選中的值、判斷是否選中等
單選框和復選框的js取值判斷
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久