脚本宝典收集整理的这篇文章主要介绍了js实例Document 对象(2),脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。
源代码
<!DOCTYPE htML> <html> <body> <form name="Form1"></form> <form name="Form2"></form> <form></form> <p>Name of First form: <script> document.wrITe(document.forms[0].name); </script></p> </body> </html>
运行结果
返回文档中的图像数
源代码
<!DOCTYPE html> <html> <body> <img border="0" src="klematis.jpg" width="150" height="113"> <img border="0" src="klematis2.jpg" width="152" height="128"> <p>Number of images: <script> document.write(document.images.length); </script></p> </body> </html>
运行结果
返回文档中第一个图像的ID
源代码
<!DOCTYPE html> <html> <body> <img id="klematis lilac" border="0" src="klematis.jpg" width="150" height="113"> <img id="klematis pink" border="0" src="klematis2.jpg" width="152" height="128"> <p>Id of first image: <script> document.write(document.images[0].id); </script></p> </body> </html>
运行结果
返回文档中的链接数
源代码
<!DOCTYPE html> <html> <body> <img src ="planets.gif" width="145" height="126" alt="Planets" uSEMap ="#planetmap"> <map name="planetmap"> <area Shape="rect" coords="0,0,82,126" href="sun.htm" alt="Sun"> <area shape="circle" coords="90,58,3" href="mercur.htm" alt="Mercury"> <area shape="circle" coords="124,58,8" href="venus.htm" alt="Venus"> </map> <p><a href="/js/">JavaScript Tutorial</a></p> <p>Number of areas/links: <script> document.write(document.links.length); </script></p> </body> </html>
运行结果
返回文档中的第一个链接的ID
源代码
<!DOCTYPE html> <html> <body> <img src ="planets.gif" width="145" height="126" alt="Planets" usemap ="#planetmap"> <map name="planetmap"> <area id="sun" shape="rect" coords="0,0,82,126" href="sun.htm" alt="Sun"> <area id="mercury" shape="circle" coords="90,58,3" href="mercur.htm" alt="Mercury"> <area id="venus" shape="circle" coords="124,58,8" href="venus.htm" alt="Venus"> </map> <p><a id="javascript" href="/js/">JavaScript Tutorial</a></p> <p>Id of first area/link: <script> document.write(document.links[0].id); </script></p> </body> </html>
运行结果
源代码
<!DOCTYPE html> <html> <body> <form name="Form1"></form> <form name="Form2"></form> <form></form> <p>Name of first form: <script> document.write(document.forms[0].name); </script></p> </body> </html>
运行结果
返回文档中的图像数
源代码
<!DOCTYPE html> <html> <body> <img border="0" src="klematis.jpg" width="150" height="113"> <img border="0" src="klematis2.jpg" width="152" height="128"> <p>Number of images: <script> document.write(document.images.length); </script></p> </body> </html>
运行结果
返回文档中第一个图像的ID
源代码
<!DOCTYPE html> <html> <body> <img id="klematis lilac" border="0" src="klematis.jpg" width="150" height="113"> <img id="klematis pink" border="0" src="klematis2.jpg" width="152" height="128"> <p>Id of first image: <script> document.write(document.images[0].id); </script></p> </body> </html>
运行结果
返回文档中的链接数
源代码
<!DOCTYPE html> <html> <body> <img src ="planets.gif" width="145" height="126" alt="Planets" usemap ="#planetmap"> <map name="planetmap"> <area shape="rect" coords="0,0,82,126" href="sun.htm" alt="Sun"> <area shape="circle" coords="90,58,3" href="mercur.htm" alt="Mercury"> <area shape="circle" coords="124,58,8" href="venus.htm" alt="Venus"> </map> <p><a href="/js/">JavaScript Tutorial</a></p> <p>Number of areas/links: <script> document.write(document.links.length); </script></p> </body> </html>
运行结果
返回文档中的第一个链接的ID
源代码
<!DOCTYPE html> <html> <body> <img src ="planets.gif" width="145" height="126" alt="Planets" usemap ="#planetmap"> <map name="planetmap"> <area id="sun" shape="rect" coords="0,0,82,126" href="sun.htm" alt="Sun"> <area id="mercury" shape="circle" coords="90,58,3" href="mercur.htm" alt="Mercury"> <area id="venus" shape="circle" coords="124,58,8" href="venus.htm" alt="Venus"> </map> <p><a id="javascript" href="/js/">JavaScript Tutorial</a></p> <p>Id of first area/link: <script> document.write(document.links[0].id); </script></p> </body> </html>
运行结果
觉得可用,就经常来吧!Javascript技巧 脚本宝典 欢迎评论哦! js技巧,巧夺天工,精雕玉琢。小宝典献丑了!
以上是脚本宝典为你收集整理的js实例Document 对象(2)全部内容,希望文章能够帮你解决js实例Document 对象(2)所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。