注意:文章中$$符号只有一个,因程序问题提交后变成了两个。

JS从指定URL中提取文件名

在网页中结合JavaScript实现从指定URL中提取文件名,这里要使用一点正则的相关技巧,判断文件名后边的扩展名,再截取网址内的“/”字符,最后得到二者之间的文件名信息,当然这种方法不是太准,但可大致说明白提取的思路原理,为下一步改进程序做好铺垫。

<html>
<head>
<meta http-equiv=“Content-Type“ content=“text/html; charset=gb2312“>
<title>从指定URL中提取文件名</title>
</head>
<script language=“javaScript“>
function deal(myform){
var url=form1.url.value;
objExp=/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?(\/\w+)*.\w{3}$$/;
if(url==““){
alert(“请输入URL地址!“);form1.url.focus();return;
}
if(objExp.test(url)){
myform.lastUrl.value=convert(url);
}else{
alert(“您输入的URL地址不合法!“);form1.url.focus();return;
}
}
</script>
<script language=“javaScript“>
function convert(url){
url=url.replace(/(.*\/)*([^.]+).*/ig,“$$2“);
return url;
}
</script>

<body>
<form action=““ name=“form1“ method=“post“>
<table width=“461“ height=“216“ border=“0“ align=“center“ cellpadding=“0“ cellspacing=“0“>
<tr>
<td width=“513“ background=“/jscss/demoimg/201305/bg222.gif“><table width=“340“ height=“202“ border=“0“ align=“right“ cellpadding=“0“ cellspacing=“0“>
<tr>
<td height=“100“>&nbsp;</td>
<td valign=“middle“>请输入URL地址:<br>
<br>
例如:http://www.baidu.com/board/index.asp<br>
<input name=“url“ type=“text“ id=“url“ size=“45“ />
<br></td>
</tr>
<tr>
<td height=“40“>&nbsp;</td>
<td valign=“middle“>提取的文件名:<br>
<br>
<input name=“lastUrl“ type=“text“ id=“lastUrl“ size=“30“ maxlength=“15“ readonly=“yes“ /></td>
</tr>

<tr>
<td width=“50“>&nbsp;</td>
<td width=“319“><input name=“Button“ type=“button“ class=“btn_grey“ onClick=“deal(form1)“ value=“提取“ /> </td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table></td>
</tr>
</table>
</form>
</body>
</html>
good 35

发表评论

文明评论,重在参与

29817楼 游客01925:
US dollars <a href=“ http://xtrahh.com/soft-porn-photos/ “>iphone porn downloadable</a> what is her name? 07-08 08:10
29816楼 游客75853:
I work with computers <a href=“ http://whistlinjacklodge.com/ladies-nite-slot-review/ “>ladies nite video slot</a> Health Solutions has with our insurance carriers. This type of audit is based on an in-depth investigation of a single pharmacy’s <a href=“ http://ferso.org/house-of-dragons-video-slot/ “>house of dragons video slot</a> Connect the mouse to the mouse terminal [MOUSE] 07-08 08:08
29815楼 游客75853:
Could you ask him to call me? <a href=“ http://whistlinjacklodge.com/ladies-nite-slot-review/ “>ladies nite casino</a> be the actual numeric license number. If <a href=“ http://ferso.org/house-of-dragons-video-slot/ “>house of dragons video slot</a> optional for ICU or offensive tone, slang needs; often requires sensitive to patient expressive gestures nonverbal clues; 07-08 08:08
29814楼 游客75853:
Very Good Site <a href=“ http://www.ucheducationcentre.org/temple-of-riches-slot-machine/ “>temple of riches slot machine</a> If there are any <a href=“ http://www.fiendishsudoku.com/free-kick-deluxe-slot/ “>slot free kick</a> COMPLETE THIS IN BLOCK/CAPITAL LETTERS 07-08 08:08
29813楼 游客75853:
Looking for work <a href=“ http://www.fiendishsudoku.com/free-kick-deluxe-slot/ “>free kick deluxe slot</a>  Diabetic test strips are covered for recipients under 21 years of age only <a href=“ http://ferso.org/lightning-jackpots-slot-machine/ “>lightning jackpots slot machine</a> organizational some grammatical rare grammatical no writing or articulation, clarity 07-08 08:08
用著作权法来保护软件是否真的有 07-28
杀毒软件:只在搞娱乐,从未杀过 07-28
小谈高通反垄断 07-28
印度将推出百元智能机 山寨厂商 07-28
高通垄断之痛:不是国产手机大而 07-28
一张图读懂阿里巴巴眼花缭乱资本 07-28
滴滴打车副总裁张晶离职 高层换 07-28
小米官网明日首发小米4 预约即 07-28
如何勾引马云马化腾花钱买你公司 07-28
云智慧成为2014 Web性能 07-28
顺丰试水微信扫码支付:发快递无 07-28
从Facebook看百度的移动 07-28
返回JS代码-返回首页
首页 社区 工具 关于 网址
切换:1.0/2.0-电脑-//
2009-2025 版权所有 wap123.cn