我可以将 exist javascript 函数调用到 jquery 函数中吗

Can I call an exist javascript function into jquery function

我可以创建一个可以调用现有 Javascript 函数的 jQuery 函数吗?但是,Javascript 函数来自不同的文件。

首先,我有一个按钮可以打开包含 form.Before 表单弹出窗口的模式对话框我想首先使用一个已经存在的函数来检查验证。

<body>
<input type="button" name="buttonform" id="buttonform" value="Open Modal Form" />
<div id="dialogform"  align = "center">
   DIALOG
<form name="myForm2" action="/action_page.php" onsubmit="return validateForm()" method="post">
 Name: <input type="text" name="fname">
<input type="submit" value="Submit">
</form>
</div>   
</body>

jQuery函数:

<script>
$(function openform(){

$("#dialogform").dialog({
    modal: true,
    autoOpen: false,
    title: "Modal Form",
    width: 700,
    height: 400,
});

$('#buttonform').click(function (){

        $('#functioncheckheader')//function to call from other javascript file
        $('#dialogform').dialog('open');     
});
})
</script>

来自不同文件的 javascript 函数示例:

function checkheader(){

if($('#company').val() == 'select')
{   alert("Please select the date in header");     }
else if($('#project').val() == 'select')
{   alert("Please select the project in header");       }
else if($('#reqType').val() == 'select')
{   alert("Please select the request type");       }
else if($('#la').val() == "")
{   alert("Please fill up the LA no.");      }
else if($('#workScope').val() == "")
{   alert("Please select the work scope.");     }

}

顺便说一句,我是 jQuery 的新人。谢谢!!

首先,在 jQuery

之后将 js 文件添加到 HTML
<html>
   <head>
       <script src="functionToUse.js"></script>
   </head>
</html>

如果您希望在 jQuery 代码中使用该文件中的函数。

$('#buttonform').click(function (){
     funcFromFile(); //function to call from other javascript file
     $('#dialogform').dialog('open');      
});