Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript函数_Javascript_Html - Fatal编程技术网

javascript函数

javascript函数,javascript,html,Javascript,Html,我有Html文档A.Html和javascript文件A.js,如何在Html正文中编写javascript代码,将函数res指定为表单中定义的按钮的onclick事件的事件处理程序 A.html------ <body> <form> <input type = "button" id="butt1" value = "Press for Results" /><br /> </form> <script type="text

我有Html文档A.Html和javascript文件A.js,如何在Html正文中编写javascript代码,将函数res指定为表单中定义的按钮的onclick事件的事件处理程序

A.html------

<body>
<form>
<input type = "button" id="butt1" value = "Press for Results" /><br />
</form>

<script type="text/javascript">

</script>
</body>

我想这就是你的意思

a、 html:

如果你想把所有的代码都放在一页上

<head>
    <script type="text/javascript">
        function res()
        {
            alert("function logic to go here");
        }
    </script>
</head>
<body>
    <form>
        <input onclick="javascript:res();" type="button" id="butt1" value="Press for Results" /><br />
    </form>
</body>

这是一个写得很糟糕的问题,但我认为你想做的是非常简单的。将外部脚本包含在

<script type="text/javascript" src="A.js"></script>
您可以在HTML中使用指定,例如:

<button onclick="res()" value="call res()">
A.html

突然

    <script type="text/javascript">
function inform(){
alert("You have activated me by clicking the grey button! Note that the event handler is added within the event that it handles, in this case, the form button event tag")
}
</script>

<form>
<input type="button" id="button" name="test" value="Click me" onclick="inform()">
</form>

我无法理解你想要达到的目的。。您是否在a.html中有一个按钮,并希望它在单击时调用a.js中定义的函数?我相信他希望有一个名为res的函数,其作用类似于按钮的onclick action。和@sira,你不必大喊大叫。@Marty是的,我想要和你说的一样的东西,但是代码将在Html Javascript中,但是我需要表单外的按钮的onclick事件javascript@Sira如果您需要外部按钮的onclick事件,那么为什么不使用jquery呢?我想这对你们来说很容易。@Nick u在表单中为button编写了onclick事件,但我需要它在表单之外…………意味着在A.html的javascript中调用A的res。js@Sira将jquery绑定事件用于按钮。容易的eh@sira我刚刚编辑了答案,希望有帮助。。。。这可能会给mozilla带来一些问题
function res() {
   ...
}
<button onclick="res()" value="call res()">
 <script type="text/javascript" src="A.js">
 <form>
   <input type="button" name="test" value="Click me" onclick="inform()">
 </form>
function inform(){
    alert("You have activated me by clicking the grey button! Note that the event handler is added within the event that it handles, in this case, the form button event tag")
    }
    <script type="text/javascript">
function inform(){
alert("You have activated me by clicking the grey button! Note that the event handler is added within the event that it handles, in this case, the form button event tag")
}
</script>

<form>
<input type="button" id="button" name="test" value="Click me" onclick="inform()">
</form>
if(condition in which you want onclick to b called)
   document.getElementById('button').click();