0

如何在我的确认删除按钮上调用多个函数?

以下是我需要调用的函数:

    function ifnull() {
                if (selected_devices_area = "") {
                    window.alert("Please select devices!");
                }
            }

    function submitForm() {

                if (confirm("Do you really want to delete these devices?")) {
                    //document.location.href = '/site/service/device/DeleteMultipleDevices.asp?siteId=<%=iSiteId%>&serviceId=<%=iServiceId%>';

                    document.device.submit();
                    window.alert('Devices successfully deleted.');

                }

按钮的 HTML:

        <tr>    
            <td><a href="/site/service/serviceinfo_main.asp?siteId=<%=iSiteId%> &crType=Delete Multiple Devices&addCr=yes&crId=<%=iCrId %>"class="btnLink">&laquo; Back</a></td>
            <td class="tdRight"><a href="javascript:ifnull();javascript:submitForm();" class="btnLink">Confirm Deletion &raquo;</a></td>
        </tr>
    </table>

我正在调用这样的函数,但它不起作用。

4

1 回答 1

2

您不需要使用“javascript:”前缀两次。代替

<a href="javascript:ifnull();javascript:submitForm();" class="btnLink">

<a href="javascript:ifnull();submitForm();" class="btnLink">

但更重要的是,如果我理解正确,如果ifnull()没有通过 - 你不想提交表格。如果是这样,请将您的ifnull()功能更改为:

function ifnull() {
   if (selected_devices_area = "") {
       window.alert("Please select devices!");
       return true
   } else {
       return false
   }
}

然后你可以改变你的submitForm()功能

function submitForm() {
   if (!ifnull() && confirm("Do you really want to delete these devices?")) {
        document.device.submit();
        // You should generate "alert('Devices successfully deleted.');" from server side
        // since as of now you don't know that is really happend
}

并将您的电话更改为

<a href="submitForm();" class="btnLink">

这种方式逻辑上更简洁。

于 2013-09-26T13:20:45.157 回答