在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML5  HTML/ jQuery 代碼問題

jQuery 代碼問題

             //對(duì)于布爾類型的屬性,不要用attr方法,應(yīng)該用prop方法。 prop用法跟attr方法一樣。
             $("#btn1").click(function () {
                 // $("#ck").attr("checked","true");
                 $("#ck").prop("checked",true);//true不能加引號(hào)
             });
             $("#btn2").click(function () {
                 $("#ck").prop("checked",false);
             });

請(qǐng)問這里的false和true為什么不需要加引號(hào),平常使用需要加引號(hào)的原因是什么?

回答
編輯回答
笨小蛋

https://developer.mozilla.org...
僅適用于類型為"checkbox" 或 "radio"元素的屬性

checked boolean: Returns / Sets the current state of the element when type is checkbox or radio.
defaultChecked boolean: Returns / Sets the default state of a radio button or checkbox as originally specified in HTML that created this object.
indeterminate boolean: indicates that the checkbox is neither on nor off. Changes the appearance to resemble a third state. Does not affect the value of the checked attribute, and clicking the checkbox will set the value to false.

建議買本書好好學(xué)學(xué)DOM和js基礎(chǔ)

2018年8月6日 10:56
編輯回答
懶豬

clipboard.png

2017年11月2日 13:46
編輯回答
不將就

checked本來就是一個(gè)bool值,你為啥要加引號(hào),加引號(hào)不變成string了嗎?

prop("checked", "false") 也會(huì)被當(dāng)成勾選對(duì)待,這肯定不是你想要的效果吧?

2018年7月20日 23:41
編輯回答
怣人

加雙引號(hào)不就是字符串了嗎?1樓貼得那張圖里已經(jīng)寫得很清楚了,是需要boolean類型的值。

真心建議先把DOM和JS的基礎(chǔ)再去擼一遍...

2017年8月13日 00:30
編輯回答
互擼娃

加引號(hào)不成字符串了,要的是布爾類型

2018年6月25日 06:10