有一个form表单
<form name="keywords" class="form_index" action="/s/" method="get">提交按钮
<input type="submit" value="Search" id="su" class="s_btn">点击这个按钮以后得到一个URL。如:http://localhost/s/?wd=Wordpress但是我想要的URL为:http://localhost/s/Wordpress听很多人都说使用JS处理一下这个表单提交,可以得到我想要的URL,就是不知道如何处理请高手帮帮忙
<form name="keywords" class="form_index" action="/s/" method="get">提交按钮
<input type="submit" value="Search" id="su" class="s_btn">点击这个按钮以后得到一个URL。如:http://localhost/s/?wd=Wordpress但是我想要的URL为:http://localhost/s/Wordpress听很多人都说使用JS处理一下这个表单提交,可以得到我想要的URL,就是不知道如何处理请高手帮帮忙
是提交到服务器端了但是URL不是客户所要求的
他们要求的是http://localhost/s/Wordpress这种形式的
但是使用get,默认会有?
<head>
<script>
function substr()
{
var str=location.href;
var index1=str.indexOf("?",0);
var index2=str.indexOf("=",0);
var newstr=str.substring(0,index1)+str.substring(index2+1,str.length);
alert(newstr);
}
</script>
</head><body>
<input type="submit" value="Search" id="su" class="s_btn" onclick="javascript:substr();">
</body>
</html>
这个列子是只能去掉一个参数名,如果多个就要加条件
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<script type="text/javascript">
function onsb(fm){
fm.action = fm.action+fm.wd.value;
alert(fm.action);
return true;
}
</script>
<body>
<form method="get" action="/s/" onsubmit="return onsb(this)">
<input type="text" name="wd" value="Wordpress">
<input type="submit" value="提交">
</form>
</body>
</html>
但是URL尾部还有参数。这个是我用您的方法得到的URL
http://localhost/s/Wordpress?wd=Wordpress
您的方法的确可以得到我想要的值
但是URL尾部还有参数。这个是我用您的方法得到的URL
http://localhost/s/Wordpress?wd=Wordpress
你正则写错了。变成var href = (location.href).replace(/\?.+?=/,"");
这样就行了。
怎样将这个值返回到URL里呢?
var href = (location.href).replace(/?kwd=/,""); 是不是就可以了?第二:这个值怎么传到URL里啊?
误人子弟啊
误人子弟啊
误人子弟啊LZ只是想要那种形式的URL,那种形式的URL跟POST有一毛钱的关系?没有,除非你用MVC。如果你用的伪静态,正确的URL应该是 http://localhost/s/(index.html)?wd=Wordpress 类似这样的,你想改成http://localhost/s/Wordpress 那你就要配置个伪静态规则。如果是urlRewrite,也是配置下规则。