jQuery mobile转换url地址及获取url中目录部分的方法
作者:goldensun 发布时间:2023-07-02 05:34:34
标签:jQuery,url
path.makeUrlAbsolute() 把相对URL转化为绝对URL
jQuery.mobile.path.makeUrlAbsolute( relUrl, absUrl )
把相对URL转化为绝对URL的方法。这个函数返回一个字符串,绝对URL。
relUrl:相对网址。类型:字符串。
absUrl:绝对网址。类型:字符串。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery.mobile.path.makeUrlAbsolute demo</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<!-- The script below can be omitted -->
<script src="/resources/turnOffPushState.js"></script>
<script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
<style>
#myResult{
border: 1px solid;
border-color: #108040;
padding: 10px;
}
</style>
</head>
<body>
<div data-role="page">
<div data-role="content">
<p>The absoulte URL used is http://foo.com/a/b/c/test.html</p>
<input type="button" value="file.html" id="button1" class="myButton" data-inline="true">
<input type="button" value="../../foo/file.html" id="button2" class="myButton" data-inline="true">
<input type="button" value="//foo.com/bar/file.html" id="button3" class="myButton" data-inline="true">
<input type="button" value="?a=1&b=2" id="button4" class="myButton" data-inline="true">
<input type="button" value="#bar" id="button5" class="myButton" data-inline="true">
<div id="myResult">The result will be displayed here</div>
</div>
</div>
<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>
</body>
</html>
path.get() 确定URL中的目录部分
jQuery.mobile.path.get( url )
url:只有一个参数。类型:字符串。
确定URL中的目录部分的实用方法。如果URL没有斜线,URL的一部分被认为是一个文件。这个函数返回一个给定的URL目录部分。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery.mobile.path.get demo</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<!-- The script below can be omitted -->
<script src="/resources/turnOffPushState.js"></script>
<script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
<style>
#myResult{
border: 1px solid;
border-color: #108040;
padding: 10px;
}
</style>
</head>
<body>
<div data-role="page">
<div data-role="content">
<input type="button" value="http://foo.com/a/file.html" id="button1" class="myButton" data-inline="true" />
<input type="button" value="http://foo.com/a/" id="button2" class="myButton" data-inline="true" />
<input type="button" value="http://foo.com/a" id="button3" class="myButton" data-inline="true" />
<input type="button" value="//foo.com/a/file.html" id="button4" class="myButton" data-inline="true" />
<input type="button" value="/a/file.html" id="button5" class="myButton" data-inline="true" />
<input type="button" value="file.html" id="button6" class="myButton" data-inline="true" />
<input type="button" value="/file.html" id="button7" class="myButton" data-inline="true" />
<input type="button" value="?a=1&b=2" id="button8" class="myButton" data-inline="true" />
<input type="button" value="#foo" id="button9" class="myButton" data-inline="true" />
<div id="myResult">The result will be displayed here</div>
</div>
</div>
<script>
$(document).ready(function() {
$( ".myButton" ).on( "click", function() {
var dirName = $.mobile.path.get( $( this ).attr( "value" ) );
$( "#myResult" ).html( String( dirName ) );
})
});
</script>
</body>
</html>
0
投稿
猜你喜欢
- 目录简述:1. 事务的四大特性2.多事务并发带来的问题3.事务的隔离级别4.演示不同隔离级别出现的问题读未提交读已提交可重复读串行化5.锁机
- 匹配文本并在其上一行追加文本问题描述Python匹配文本并在其上一行追加文本test.txtabcde1.读进列表后覆盖原文件 d
- 描述Fashion Mnist 是一个类似于 Mnist 的图像数据集. 涵盖 10 种类别的 7 万 (6 万训练集 + 1 万测试集)
- 本文实例讲述了Django restframework 框架认证、权限、限流用法。分享给大家供大家参考,具体如下:概述Django Rest
- 一、name_scopewith tf.name_scope(name):name_scope: 为了更好地管理变量的命名空间而提出的。比如
- 分享mysql 5.7 docker 主从复制架构搭建教程,供大家参考,具体内容如下环境版本:MySQL : 5.7.13Doc
- 如果你象作者一样记性不好,那么你可能根本记不住人们的名字。我遇到人时,多半只是点点头,问句“吃了嘛!”,而且期望问候到此为止 。如果还需要表
- Pytorch中torch.nn.Softmax的dim参数使用含义涉及到多维tensor时,对softmax的参数dim总是很迷,下面用一
- 修改my.ini或my.conf,将sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_US
- 有些人说py中有两个函数可以实现对所有函数的了解以及使用,其中之一,就是我们今天要讲解的help函数。有些小伙伴可能比较陌生,但是另一个函数
- 为了得到更加清晰的图像我们需要通过技术对图像进行处理,比如使用对比度增强的方法来处理图像,对比度增强就是对图像输出的灰度级放大到指定的程度,
- 注:IE8以前的版本均不支持该特性为了向文档中插入生成内容,可以使用:before与:after伪元素。如,我想在所有链接的后面加上&quo
- 前后端分离的开发模式,原本觉得没什么稀奇的玩艺,在最近参与的一个大型项目中,让我有了更深的理解。前后端分离的开发模式:系统分析阶段,系分和前
- transforms.Resize()的简单使用简单来说就是调整PILImage对象的尺寸,注意不能是用io.imread或者cv2.imr
- 节日用心准备的礼物,使用python画玫瑰和爱心,供大家参考,具体内容如下#!/usr/bin/env python#coding=utf-
- 阅读别人的python源码时碰到了这个yield这个关键字,各种搜索终于搞懂了,在此做一下总结:通常的for...in...循环中,in后面
- 定义和用法fopen() 函数打开文件或者 URL。如果打开失败,本函数返回 FALSE。语法fopen(filename,mode,inc
- 本文实例为大家分享了python实现桌面壁纸切换功能的具体实现方法,供大家参考,具体内容如下大体分为两个部分一、利用爬虫爬取壁纸第一部分爬取
- 目录前言一、样式穿透1. 什么是样式穿透?2. 如何使用?二、混入1. 什么是混入?2. 如
- 本文实例总结了GO语言基本数据类型。分享给大家供大家参考。具体如下:1、注释(与C++一样)行注释://块注释:/* ...*/2、标识符可