使用纯javascript实现创建表单并提交的方法
- 5272
- jQuery
- 3
- super_dodo
- 2014/02/07
在一些应用中需要点击一个按钮或者链接实现删除或者影藏等更多的功能模块.且该模块需要实现表单的方式进行提交相关的信息验证到指定的方法.下面就是使用纯javascript进行的方法示例.可模仿改造后使用.
<ul class="actions">
<li><a href="http://localhost/nodes/91/edit" rel="inspect">编辑</a></li>
<li><a href="http://localhost/nodes/91/hide" onclick="javascript:hide();return false;">隐藏</a></li>
<li><a href="http://localhost/nodes/91/del" onclick="javascript:del();return false;">删除</a></li>
<li><a href="http://localhost/nodes/91/del" onclick="if(confirm('..')){...del的函数体};return false;">删除</a></li>
</ul>
<script type="text/javascript">
//删除的函数方法--亦可压缩组合写在一行里面
function del(){
if(confirm('Are you sure you wish to delete this node?')){
var f = document.createElement('form');
f.style.display = 'none';
this.parentNode.appendChild(f);
f.method = 'POST';
f.action = this.href;
var m = document.createElement('input');
m.setAttribute('type', 'hidden');
m.setAttribute('name', '_method');
m.setAttribute('value', 'delete');
f.appendChild(m);
var s = document.createElement('input');
s.setAttribute('type', 'hidden');
s.setAttribute('name', 'authenticity_token');
s.setAttribute('value', 'lhzUtuxOsuZtuI44IVH');
f.appendChild(s);
f.submit();
};
return false;
}
//隐藏的函数方法
function hide(){
var f = document.createElement('form');
f.style.display = 'none';
this.parentNode.appendChild(f);
f.method = 'POST';
f.action = this.href;
var m = document.createElement('input');
m.setAttribute('type', 'hidden');
m.setAttribute('name', '_method');
m.setAttribute('value', 'put');
f.appendChild(m);
var s = document.createElement('input');
s.setAttribute('type', 'hidden');
s.setAttribute('name', 'authenticity_token');
s.setAttribute('value', 'lhzUtuxOsuZtuI44IVH');
f.appendChild(s);
f.submit();
return false;
}
</script>
The heart wants what the heart wants. 心随所愿。
- MySQL入门很简单—索引视图触发器
- Yii2使用(设置,获取,删除)cookie的方法
- 第24章 X Window设置介绍 -《鸟哥的Linux》
- Yii2使用$this->context获取当前的Module、Controller(控制器)、Action等
- 雷军在联想的演讲:全场无言,除了掌声!
- Apache的vhost中配置默认访问入口index-test.php的方法(Yii)
- PHP程序查询IP地址归属地的方法
- Discuz! x3.2发帖要操作哪些数据表
- WordPress数据库备份之后本地还原失败的原因MySQL5.7
- Yii框架 $this->redirect与$this->createUrl 的路由设置
相关阅读
- 通过Google API客户端访问Google Play帐户报告PHP库
- PHP执行文件的压缩和解压缩方法
- 消息中间件MQ与RabbitMQ面试题
- 如何搭建一个拖垮公司的技术架构?
- Yii2中ElasticSearch的使用示例
热门文章
- 通过Google API客户端访问Google Play帐户报告PHP库
- PHP执行文件的压缩和解压缩方法
- 消息中间件MQ与RabbitMQ面试题
- 如何搭建一个拖垮公司的技术架构?
- Yii2中ElasticSearch的使用示例
最新文章
- 通过Google API客户端访问Google Play帐户报告PHP库
- PHP执行文件的压缩和解压缩方法
- 消息中间件MQ与RabbitMQ面试题
- 如何搭建一个拖垮公司的技术架构?
- Yii2中ElasticSearch的使用示例

