js实例Anchor 对象

发布时间:2018-11-21 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了js实例Anchor 对象脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。
返回和设置链接的charset属性

代码

 <!DOCTYPE htML> <html> <body>  <a id="w3s" charset="ISO-8859-1" href="https://www.w3cschool.cc/">W3Cschool</a><br>  <script> document.wrITe("Return charset of link: "); document.write(document.getElementById(&#39;w3s').charset); document.write("<br><br>"); </script>  <a id="GOOGLE" href="https://www.google.COM/">Google</a><br>  <script> document.getElementById('google').charset="utf-8"; document.write("Set charset of link to: "); document.write(document.getElementById('google').charset); </script>  </body> </html> 

&nbsp;

运行结果

返回和设置链接的href属性

源代码

 <!DOCTYPE html> <html> <body>  <p><a id="w3s" href="https://www.w3cschool.cc/">W3Cschool</a></p>  <script> document.write("Return href of link: "); document.write(document.getElementById('w3s').href); </script>  </body> </html> 

 

运行结果

返回和设置链接的hreflang属性

源代码

 <!DOCTYPE html> <html> <body>  <a id="w3s" hreflang="en-us" href="https://www.w3cschool.cc/">W3Cschool</a><br>  <script> document.write("Return hreflang of link: "); document.write(document.getElementById('w3s').hreflang); document.write("<br><br>"); </script>  <a id="google" href="https://www.google.com/">Google</a><br>  <script> document.getElementById('google').hreflang="no"; document.write("Set hreflang of link to: "); document.write(document.getElementById('google').hreflang); </script>  </body> </html> 

 

运行结果

返回一个的名字

源代码

 <!DOCTYPE html> <html> <body>  <p><a href="#C6">See also Chapter 6</a></p>  <h2>Chapter 1</h2> <p>This chapter explains ba bla bla</p>  <h2>Chapter 2</h2> <p>This chapter explains ba bla bla</p>  <h2>Chapter 3</h2> <p>This chapter explains ba bla bla</p>  <h2>Chapter 4</h2> <p>This chapter explains ba bla bla</p>  <h2>Chapter 5</h2> <p>This chapter explains ba bla bla</p>  <h2><a id="c6" name="C6">Chapter 6</a></h2> <p>This chapter explains ba bla bla</p>  <script> document.write("Return name of anchor: "); document.write(document.getElementById("c6").name); </script>  </body> </html>

 

运行结果

返回当前的文件和链接的文档之间的关系

源代码

 <!DOCTYPE html> <html> <body>  <p><a id="func" rel="friend" href="https://www.functravel.com/">Cheap Flights</a></p>  <script> document.write("The relationship between the current document and the linked document: "); document.write(document.getElementById("func").rel); </script>  </body> </html>

 

运行结果

改变链接的target属性

源代码

 <!DOCTYPE html> <html> <head> <script> function changeTarget() { document.getElementById('w3s').target="_blank"; } </script> </head>  <body> <a id="w3s" href="https://www.w3cschool.cc">Visit W3Cschool</a> <br><br> <input type="button" onclick="changeTarget()" value="Change target">  <p>Try the link before and after you have Pressed the button!</p>  </body> </html> 

 

运行结果

返回一个链接的type属性的值

源代码

 <!DOCTYPE html> <html> <body>  <p><a id="w3c" type="text/html" href="https://www.w3cschool.cc">W3Cschool</a></p>  <script> document.write("Return value of type attribute in link: "); document.write(document.getElementById("w3c").type); </script>  </body> </html> 

 

运行结果


返回和设置链接的charset属性

源代码

 <!DOCTYPE html> <html> <body>  <a id="w3s" charset="ISO-8859-1" href="https://www.w3cschool.cc/">W3Cschool</a><br>  <script> document.write("Return charset of link: "); document.write(document.getElementById('w3s').charset); document.write("<br><br>"); </script>  <a id="google" href="https://www.google.com/">Google</a><br>  <script> document.getElementById('google').charset="utf-8"; document.write("Set charset of link to: "); document.write(document.getElementById('google').charset); </script>  </body> </html> 

 

运行结果

返回和设置链接的href属性

源代码

 <!DOCTYPE html> <html> <body>  <p><a id="w3s" href="https://www.w3cschool.cc/">W3Cschool</a></p>  <script> document.write("Return href of link: "); document.write(document.getElementById('w3s').href); </script>  </body> </html> 

 

运行结果

返回和设置链接的hreflang属性

源代码

 <!DOCTYPE html> <html> <body>  <a id="w3s" hreflang="en-us" href="https://www.w3cschool.cc/">W3Cschool</a><br>  <script> document.write("Return hreflang of link: "); document.write(document.getElementById('w3s').hreflang); document.write("<br><br>"); </script>  <a id="google" href="https://www.google.com/">Google</a><br>  <script> document.getElementById('google').hreflang="no"; document.write("Set hreflang of link to: "); document.write(document.getElementById('google').hreflang); </script>  </body> </html> 

 

运行结果

返回一个锚的名字

源代码

 <!DOCTYPE html> <html> <body>  <p><a href="#C6">See also Chapter 6</a></p>  <h2>Chapter 1</h2> <p>This chapter explains ba bla bla</p>  <h2>Chapter 2</h2> <p>This chapter explains ba bla bla</p>  <h2>Chapter 3</h2> <p>This chapter explains ba bla bla</p>  <h2>Chapter 4</h2> <p>This chapter explains ba bla bla</p>  <h2>Chapter 5</h2> <p>This chapter explains ba bla bla</p>  <h2><a id="c6" name="C6">Chapter 6</a></h2> <p>This chapter explains ba bla bla</p>  <script> document.write("Return name of anchor: "); document.write(document.getElementById("c6").name); </script>  </body> </html>

 

运行结果

返回当前的文件和链接的文档之间的关系

源代码

 <!DOCTYPE html> <html> <body>  <p><a id="func" rel="friend" href="https://www.functravel.com/">Cheap Flights</a></p>  <script> document.write("The relationship between the current document and the linked document: "); document.write(document.getElementById("func").rel); </script>  </body> </html>

 

运行结果

改变链接的target属性

源代码

 <!DOCTYPE html> <html> <head> <script> function changeTarget() { document.getElementById('w3s').target="_blank"; } </script> </head>  <body> <a id="w3s" href="https://www.w3cschool.cc">Visit W3Cschool</a> <br><br> <input type="button" onclick="changeTarget()" value="Change target">  <p>Try the link before and after you have PRessed the button!</p>  </body> </html> 

 

运行结果

返回一个链接的type属性的值

源代码

 <!DOCTYPE html> <html> <body>  <p><a id="w3c" type="text/html" href="https://www.w3cschool.cc">W3Cschool</a></p>  <script> document.write("Return value of type attribute in link: "); document.write(document.getElementById("w3c").type); </script>  </body> </html> 

 

运行结果


觉得可用,就经常来吧!Javascript技巧 脚本宝典 欢迎评论哦! js技巧,巧夺天工,精雕玉琢。小宝典献丑了!

脚本宝典总结

以上是脚本宝典为你收集整理的js实例Anchor 对象全部内容,希望文章能够帮你解决js实例Anchor 对象所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。