简体   繁体   English

如何在javascript中调用另一个函数?

[英]how to call another function in javascript?

how do i call the doSubmit() function from the conFirmUpload() when the confirm msg box is true? 确认消息框为true时,如何从conFirmUpload()调用doSubmit()函数?

<script type="text/javascript">
    function confirmUpload() {
        if (confirm("Are you sure want to upload '" + document.getElementById("txtWS").value + "' ?") == true) {
            return true;
        }
        else
            return false;
    }

    function doSubmit(btnUpload) {
        if (typeof(Page_ClientValidate) == 'function' && Page_ClientValidate() == false) { 
            return false;
        }    
        btnUpload.disabled = 'disabled';
        btnUpload.value = 'Processing. This may take several minutes...';
        <%= ClientScript.GetPostBackEventReference(btnUpload, string.Empty) %>;    
    }
</script>
var btnUpload = document.getElementById('buttonId');
doSubmit(btnUpload);

Put that in your if-block. 将其放在您的if块中。 Make sure the button has an ID. 确保按钮具有ID。

Without knowing more What about this? 不知道什么呢?

function confirmUpload(btnUpload) {
    if (confirm("Are you sure want to upload '" + document.getElementById("txtWS").value + "' ?") == true) {
        doSubmit(btnUpload);
    }
    else
        return false;
}
function confirmUpload() {
    if (confirm("Are you sure want to upload '" + document.getElementById("txtWS").value + "' ?") == true) {
        var btnUpload = document.getElementById('<%= btnUpload.ClientID %>');
        doSubmit(btnUpload);
    }
}

Change the method prototype as 将方法原型更改为

function confirmUpload(obj) {
//Do some thing
}

Where obj the the button you are clicking on obj是您要单击的按钮

Call this method as 将此方法称为

**onclick="javaScript:confirmUpload(this)"**

Now in that if part call another method like 现在,如果部分调用另一个方法

if (confirm("Are you sure want to upload '" + document.getElementById("txtWS").value
    +     "' ?") == true) {
    doSubmit(obj);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM