時(shí)間:2023-02-20 06:42:01 | 來(lái)源:建站知識(shí)
時(shí)間:2023-02-20 06:42:01 來(lái)源:建站知識(shí)
html中id屬性和name屬性的區(qū)別是什么:在html中,id屬性和name屬性都是提供標(biāo)識(shí)符,表示HTML元素標(biāo)簽的。那么它們之間有什么區(qū)別?本篇文章就給大家簡(jiǎn)單比較一下id屬性和name屬性,介紹id屬性和name屬性之間的區(qū)別是什么,希望對(duì)大家有所幫助。<p id="p1">測(cè)試文本!測(cè)試文本!</p><p id="p2">測(cè)試文本!測(cè)試文本!</p>
<script>document.getElementById("p2").style.color="red";</script>
id屬性是普遍兼容的,對(duì)任何元素都有效。且id屬性的值是區(qū)分大小寫的,每個(gè)id值都應(yīng)該是唯一的。例:<div id="demo"> <div id="a">div標(biāo)簽,id值為a</div> <p id="A">p標(biāo)簽,id值為A</p></div>
#a{ color: red;}#A{ color: pink;}
效果圖:<form action="" method="get"> 最喜歡水果?<br /><br /> <label><input name="Fruit" type="radio" value="" />蘋果 </label> <br /> <label><input name="Fruit" type="radio" value="" />桃子 </label> <br /> <label><input name="Fruit" type="radio" value="" />香蕉 </label> <br /> <label><input name="Fruit" type="radio" value="" />梨 </label> <br /> <label><input name="Fruit" type="radio" value="" />其它 </label> <br /> </form>
效果圖:<script type="text/javascript">function getElements() { var x=document.getElementsByName("myInput"); alert(x.length); }</script> <input name="myInput" type="text" size="20" /><br /><input name="myInput" type="text" size="20" /><br /><input name="myInput" type="text" size="20" /><br /><br /><input type="button" onclick="getElements()" value="名為 'myInput' 的元素有多少個(gè)?" />
效果圖:關(guān)鍵詞:屬性,區(qū)別
客戶&案例
營(yíng)銷資訊
關(guān)于我們
客戶&案例
營(yíng)銷資訊
關(guān)于我們
微信公眾號(hào)
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。