【发布时间】:2011-11-01 18:30:29
【问题描述】:
我有一个带有 jquery 代码的按钮,可以清除来自的所有数据。
<button id="reset">Reset</button>
jQuery 代码如下所示:
$("#reset").click(function()
{
$(':input').val('');
...LOTS and lots of more code...
$("#id").focus();
});
另外,与按钮分开...我有一个 ajax/php,如果成功,我希望它调用 $("#reset").click() 函数。
-我不想复制和粘贴代码。
如何调用该函数?
这不起作用:
$("#reset").click();
这是我的 ajax 的“虚拟样本”,只是显示我想要做什么:
//AJAX
//#new
$("#add").click(function()
{
//START:$.post
$.post( "ajax.php" ,
{...var...},
function(msg)
{
if( msg == 1 )
{ //Successful
...code...
$("#reset").click();
...more code...
} //end: if
else
{ ...else code...} //end: if.else
}//end: $.post.function
); //END:$.post
}); //END:ajax
【问题讨论】: