use*_*259 1 html javascript jquery
我想调用click事件,然后按照href url.
HTML链接:
<a class="autoSave" href="?year=2013&week=42">?</a>
Run Code Online (Sandbox Code Playgroud)
JS:
$(document).ready(function() {
$('.autoSave').click(function(event){
event.preventDefault();
$('.submitForm').click(); //HTML Form that I'm wanting a submit to happen
window.location = $(this).attr('href');
});
});
Run Code Online (Sandbox Code Playgroud)
上面的代码将跟随网址,而不是提交表单.如果省略window.location调用,则提交有效.
您不必等待.click()事件完全处理才能调用window.location.
您应该序列化您的表单,通过ajax(.post()例如)发布它,然后,在回调中.post(),更改您的页面:
$(document).ready(function() {
$('.autoSave').click(function(event){
event.preventDefault();
var serializedData = $('#yourForm').serialize(); //For example
$.post('your/path/to/form/validator', serializedData, function(){
window.location = $(this).attr('href');
});
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2863 次 |
| 最近记录: |