这次给大家带来jQuery操作url地址(附代码),jQuery操作url地址的注意事项有哪些,下面就是实战案例,一起来看一下。
path.makeUrlAbsolute() 把相对URL转化为绝对URL
jQuery.mobile.path.makeUrlAbsolute( relUrl, absUrl )
把相对URL转化为绝对URL的方法。这个函数返回一个字符串,绝对URL。
relUrl:相对网址。类型:字符串。
absUrl:绝对网址。类型:字符串。
nbsp;html> <meta> <meta> <title>jQuery.mobile.path.makeUrlAbsolute demo</title> <link> <script></script> <!-- The script below can be omitted --> <script></script> <script></script> <style> #myResult{ border: 1px solid; border-color: #108040; padding: 10px; } </style><p> </p><p> </p><p>the absoulte url used is http://foo.com/a/b/c/test.html</p> <input> <input> <input> <input> <input> <p>The result will be displayed here</p> <script> $(document).ready(function() { $( ".myButton" ).on( "click", function() { var absUrl = $.mobile.path.makeUrlAbsolute( $( this ).attr( "value" ), "http://foo.com/a/b/c/test.html" ); $( "#myResult" ).html( absUrl ); }) }); </script>
path.get() 确定URL中的目录部分
jQuery.mobile.path.get( url )
url:只有一个参数。类型:字符串。
确定URL中的目录部分的实用方法。如果URL没有斜线,URL的一部分被认为是一个文件。这个函数返回一个给定的URL目录部分。
nbsp;html> <meta> <meta> <title>jQuery.mobile.path.get demo</title> <link> <script></script> <!-- The script below can be omitted --> <script></script> <script></script> <style> #myResult{ border: 1px solid; border-color: #108040; padding: 10px; } </style> <p> </p><p> <input> <input> <input> <input> <input> <input> <input> <input> <input> </p><p>The result will be displayed here</p> <script> $(document).ready(function() { $( ".myButton" ).on( "click", function() { var dirName = $.mobile.path.get( $( this ).attr( "value" ) ); $( "#myResult" ).html( String( dirName ) ); }) }); </script>
相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读: