php – 使用一个窗体发送相同的输入到不同的操作
发布时间:2020-12-13 16:37:56 所属栏目:PHP教程 来源:网络整理
导读:我有两个输入字段,我想将相同的数据发布到两个不同的php文件,具体取决于点击的任何按钮. 在我的情况下,数据只进入foo.php,但不是进入excel.php. 我想要数据去excel.php,如果第二个按钮被按下. JS: $(function() { $("#from").datepicker({ defaultDate: "+1
我有两个输入字段,我想将相同的数据发布到两个不同的php文件,具体取决于点击的任何按钮.
在我的情况下,数据只进入foo.php,但不是进入excel.php. 我想要数据去excel.php,如果第二个按钮被按下. JS: $(function() { $("#from").datepicker({ defaultDate: "+1w",changeMonth: true,numberOfMonths: 3,onClose: function(selectedDate) { $("#to").datepicker("option","minDate",selectedDate); } }); $("#to").datepicker({ defaultDate: "+1w",onClose: function(selectedDate) { $("#from").datepicker("option","maxDate",selectedDate); } }); }); HTML: <form action="foo.php" method="post"> <label for="from">From</label> <input type="text" id="from" name="from" /> <label for="to">to</label> <input type="text" id="to" name="to" /> <br> <input type="submit" value="Viewchart"> </form> <form action="excel.php" method="post"> <input type="submit" value="Download Excel file"> </form>
点击按钮时可以更改动作属性,如下所示:
$(function() { $( ".actionable" ).click( function() { $('#myForm').attr('action',$(this).data("action")); $('#myForm').submit(); }); }); 并将下一个data- *属性设置为您的按钮: <form name="form" id="myForm" method="post"> <input type="submit" class="actionable" value="Viewchart" data-action="foo.php"/> <input type="submit" class="actionable" value="Excel" data-action="excel.php"/> </form> 你可以看看它如何工作here. 相关链接: >您可以在这里阅读更多关于data- *属性:http://www.w3schools.com/tags/att_global_data.asp
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |