使用jquery修改表单的提交地址基本思路
更新时间:2014年06月04日 15:49:26 作者:
使用jquery选择器得到对应表单的jquery对象,然后使用attr方法修改对应的action,需要的朋友可以参考下
基本思路:
通过使用jquery选择器得到对应表单的jquery对象,然后使用attr方法修改对应的action
示例程序一:
默认情况下,该表单会提交到page_one.html
点击button之后,表单的提交地址就会修改为page_two.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>jquery test</title>
<script src="jquery-1.11.1.min.js"></script>
</head>
<body>
<div>
<form action="page_one.html" id="qianshou">
<input type="text"/>
<input type="submit" value="提 交"/>
</form>
</div>
<div>
<button name="update">修改form的提交地址为page_two.html</button>
</div>
</body>
<script>
var $fun = $('button[name=update]');
$fun.click(function(){
$('form[id=qianshou]').attr('action','page_two.html');
});
</script>
</html>
示例程序二:
form本来的action地址是page_one.html,通过jquery直接修改为page_two.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>jquery test</title>
<script src="jquery-1.11.1.min.js"></script>
</head>
<body>
<div>
<form action="page_one.html" id="qianshou">
<input type="text"/>
<input type="submit" value="提 交"/>
</form>
</div>
</body>
<script>
$('form[id=qianshou]').attr('action','page_two.html');
</script>
</html>
通过使用jquery选择器得到对应表单的jquery对象,然后使用attr方法修改对应的action
示例程序一:
默认情况下,该表单会提交到page_one.html
点击button之后,表单的提交地址就会修改为page_two.html
复制代码 代码如下:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>jquery test</title>
<script src="jquery-1.11.1.min.js"></script>
</head>
<body>
<div>
<form action="page_one.html" id="qianshou">
<input type="text"/>
<input type="submit" value="提 交"/>
</form>
</div>
<div>
<button name="update">修改form的提交地址为page_two.html</button>
</div>
</body>
<script>
var $fun = $('button[name=update]');
$fun.click(function(){
$('form[id=qianshou]').attr('action','page_two.html');
});
</script>
</html>
示例程序二:
form本来的action地址是page_one.html,通过jquery直接修改为page_two.html
复制代码 代码如下:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>jquery test</title>
<script src="jquery-1.11.1.min.js"></script>
</head>
<body>
<div>
<form action="page_one.html" id="qianshou">
<input type="text"/>
<input type="submit" value="提 交"/>
</form>
</div>
</body>
<script>
$('form[id=qianshou]').attr('action','page_two.html');
</script>
</html>
相关文章
Asp.net下利用Jquery Ajax实现用户注册检测(验证用户名是否存)
最近在朋友做个网站http://www.smarteas.net/,其中用实现用户注册这功能,最近网站做到了尾声,我也就把其它有些技术和大家分享一下。2010-09-09
jQuery实现浏览器之间跳转并传递参数功能【支持中文字符】
这篇文章主要介绍了jQuery实现浏览器之间跳转并传递参数功能,具有支持中文字符传输的功能,涉及jQuery编码转换、事件响应、页面跳转等相关操作技巧,需要的朋友可以参考下2018-03-03
Jquery ajax不能解析json对象,报Invalid JSON错误的原因和解决方法
我们知道Invalid JSON错误导致的json对象不能解析,一般都是服务器返回的json字符串的语法有错误。这种情况下,我们只需要仔细的检查一下json就可以解决问题。2010-03-03


最新评论