我有这样的表格
<form name="test" action="test/test_new" />
<input type="text" />
<input type="submit" value="search"/>
<input type="button" value="download"/>
我甚至需要点击下载按钮。例如。如果我点击下载,则应提交为text/text_new.xls
而不是text/text_new
。我怎么能这样做。
答案 0 :(得分:27)
将id添加到按钮并尝试此
$('#downloadButton').click(function(){
$('form[name=test]').attr('action','test/test_new.xls');
$('form[name=test]').submit();
});
答案 1 :(得分:0)
<强> HTML 强>
<input type="button" value="download" id="dwnld"/>
<强> JS 强>
$('#dwnld').click(function(){
var form = $(this).closest('form');
form.attr('action',form.attr('action')+'.xls').trigger('submit');
});
或
<强> HTML 强>
<form name="test" action="test/test_new" id="formID"/>
<input type="button" value="download" id="dwnld"/>
<强> JS 强>
$('#dwnld').click(function(){
form=$('#formID')
form.attr('action',form.attr('action')+'.xls').trigger('submit');
});
答案 2 :(得分:0)
HTML
<form name="test" id="form-id" action="test/test_new" />
<input type="text" />
<input type="button" class="submit" value="search" data-action="test/test_new" />
<input type="button" class="submit" value="download" data-action="test/test_new.xls" />
<input type="button" class="submit" value="another" data-action="test/test_newer" />
JS
$(document).on('click', 'input.submit', function () {
var form = $('#form-id');
var action = $(this).data('action');
form.attr('action', action);
form.submit();
});