2014-12-02 55 views
0

我有不同的url和2 CHtml::link()Yii CHtml :: link()示例

我的表单方法得到。

我想要什么:当点击在1个CHtml::link() - 提交表单使用example.com/first方法得到 我想要什么:当点击2 CHtml::link() - 提交表单使用方法后

example.com/second

这是可能的吗?我的意思是我需要改变表单方法为不同的提交按钮和操作。

回答

1

您可以从JavaScript代码提交表单:

$('#myLink1', '#myLink2').on('click', function(e){ 
    e.preventDefault(); 
    var method = $(this).attr('href')=='example.com/first' ? 'GET':'POST'; 
    $('#myFrom').attr(
     'action', 
     $(this).attr('href') //href attribute should contain appropriate url 
    ).attr(
     'method', 
     method 
    ).submit(); 
}); 

您也可以使用jquery form plugin在阿贾克斯的方式发送表单:

$('#myLink1').on('click', function(e){ 
    e.preventDefault(); 
    $('#myForm').ajaxSubmit({ 
     url: $(this).attr('href'), 
     type: 'GET', 
     success: function(){/*your code here*/} 
    }); 
}); 
$('#myLink2').on('click', function(e){ 
    e.preventDefault(); 
    $('#myForm').ajaxSubmit({ 
     url: $(this).attr('href'), 
     type: 'POST', 
     success: function(){/*your code here*/} 
    }); 
}); 
相关问题