Mil*_*ilk 5 html javascript jquery post query-string
我在一个类似的页面上http://example.com?query=value有一个表单<form id="formId" method="POST">。
http://example.com在没有查询字符串的情况下提交表单的最佳方式是什么?
我目前正在尝试:
$('#formId').submit(function(e){
e.preventDefault();
var url = window.location.href;
if (url.indexOf("?") != -1){
$('#formId').attr('action', url.split("?")[0]);
}
$('#formId').submit();
});
Run Code Online (Sandbox Code Playgroud)
但它似乎不起作用。
我更喜欢 javascript/jQuery 解决方案,因为这种模式在网站中很常见
例如,与其尝试更改提交操作,不如仅查找没有action属性的表单并进行适当的设置
jQuery(function($) {
$('form:not([action])').attr('action', location.pathname);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3456 次 |
| 最近记录: |