【问题标题】:Jquery Change form action on submitJquery 在提交时更改表单操作
【发布时间】:2017-05-23 21:39:24
【问题描述】:

我有一个基于 Spring Web 模型-视图-控制器 (MVC) 框架的项目。 Spring Web 模型-视图-控制器 (MVC) 框架的版本是 3.2.8。 我想更改提交按钮上的表单操作。所以这是我的代码,但根本没有改变任何东西!

<script type="text/javascript">
    $('#awardProductsButton').click(function(){
       $('#devicesFormId').attr('action', 'test');
    });
</script>

<form:form commandName="devicesForm" name="devicesForm" id="devicesFormId" method="post"     
action="${contextPath}/newdesign/manage/devices/${devicesForm.devices.id" htmlEscape="yes" enctype="multipart/form-data">   

<button id="awardProductsButton" class="btn btn-primary" type="submit">AWARD product/s</button>

 </form:form>

我也试过

$('#awardProductsButtonId').submit(function(event){
            alert ('test');
            event.preventDefault();
            $('#deviceFormId').attr('action', '${contextPath}/newdesign/manage/device/${deviceForm.device.id}');
        });

但连警报都没有显示

【问题讨论】:

标签: javascript jquery html jsp spring-mvc


【解决方案1】:

你只需要event.preventDefault().submit read-more

<script type="text/javascript">
    $('#devicesFormId').submit(function(event){
       event.preventDefault()
       $('#devicesFormId').attr('action', 'test');
       //$(this).attr('action', 'test');
    });
</script>

【讨论】:

  • 只是好奇..为什么这不会成为一个无限循环?表格不会一直重新提交吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-11-16
  • 1970-01-01
  • 2016-11-15
  • 1970-01-01
  • 1970-01-01
  • 2013-07-13
  • 2011-12-03
相关资源
最近更新 更多