2017-01-09 7 views
-1

私はSpring Web model-view-controller(MVC)フレームワークに基づくプロジェクトを持っています。 Spring Web Model-View-Controller(MVC)フレームワークのバージョンは3.2.8です。 と送信ボタンのフォームアクションを変更したいと思います。だから私のコードはありますが、何も変わらないのです!Jquery投稿時にフォームアクションを変更する

<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> 

uは「= `タイプを削除しようとしなかった私も、

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

を試みたが、でも、アラートが

+0

が必要ボタンのタグからattribuiteを送信しますか? –

+1

可能重複 - http://stackoverflow.com/questions/14375144/jquery-prevent-default-then-continue-default –

+1

あなたのコードが動作します。 https://jsfiddle.net/qc1fo7wq/ –

答えて

1

を表示されないあなただけのevent.preventDefault().submitread-more

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