2014-11-22 69 views
0

我有這種JQuery方法,我在同一個文檔中的幾個表單中使用,只是使用不同的函數名。 我需要能夠調用<input type=button onClick="??"> 中的特定表單我無法使其工作。從輸入提交JQuery函數= button onClick

這裏是我的腳本需要調用/變更:

function ConvertFormToJSON(form) 
{ 
    var array = $(form).serializeArray(); 
    var json = {}; 
    json["comm_type"] = "SFTP"; 
    jQuery.each(array, function() { 
    json[this.name] = this.value || ''; 
    }); 
    return json; 
} 

$(document).ajaxStart(function() { 
    $("body").css("cursor","wait"); 
}).ajaxStop(function() { 
    $("body").css("cursor","default"); 
}) 

$(document).ready(function() { 
    $("#sftp_advanced_fieldset").puifieldset({toggleable: true, collapsed: true, toggleDuration: 0}); 
    $("#sftp_help").puifieldset({toggleable: true, collapsed: true, toggleDuration: 0}); 

    $("#test_sftp").bind('submit', function(event){ 
    // event.preventDefault(); //Why would you cancel default action of submit?      
    var jsonRequest = JSON.stringify(ConvertFormToJSON(this)); 
    //alert(jsonRequest); 
    $("#results").html(""); 

    $.ajax({ 
     type: "POST", 
     url: "TEST",       
     data: jsonRequest, 
     dataType: "json" 
    }).always(function(results) { 
     var jsonResults = JSON.stringify(results); 
     if (results.status == "Succeeded") { 
     jQuery("#results").html("<h1 style=\"color: #00cc00; \">" + results.status + "</h1>"); 
    }); 

等...等...

當然與$("#test_sftp").bind('submit', function(event){ 中它工作正常,從input type="submit"但我不想這樣做。

任何幫助非常感謝。

謝謝。

回答

0

<input type="button" value="Button" onclick="javascript:doSomething()">

會工作得很好