简体   繁体   English

尝试从外部JS文件调用函数

[英]trying to call function from an external JS file

i have a very simple asp.net code but my code doesnt make any sense and after run there would be nothing happen . 我有一个非常简单的asp.net代码,但是我的代码没有任何意义,运行后将不会发生任何事情。

I'm using external java script file and trying to run my Script from my asp page and in the button object . 我正在使用外部Java脚本文件,并尝试从我的asp页面和button对象中运行我的脚本。

Its my asp code : 它是我的asp代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="WebApplication2.test" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head ">
    <title></title>
    <script src="Script/Script_Validate.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server" >
<div>
    <asp:Button runat="server" Text="aaaaaa" OnClientClick="valid();"  />
</div>
</form>
</body>
</html>

Its my JS's file content : 它是我的JS的文件内容:

function valid()
{
    alert("Hello! I am an alert box!!");
}

please help . 请帮忙 。

Your code works for me. 您的代码对我有用。 Do you definitely have a "Script" folder? 您肯定有一个“脚本”文件夹吗? Is the name of the file correct? 文件名正确吗? Do you have JavaScript enabled on your browser? 您的浏览器是否启用了JavaScript?

The only problem I can see with your code is your head tag has a single quotation mark ("). Maybe this should be runat="server"? 我在您的代码中看到的唯一问题是您的head标签有一个单引号(“)。也许这应该是runat =” server“?

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

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