我是靠谱客的博主 舒心钢笔,这篇文章主要介绍使用jquery修改表单的提交地址基本思路,现在分享给大家,希望可以做个参考。

基本思路:

通过使用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修改表单内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(180)

评论列表共有 0 条评论

立即
投稿
返回
顶部