一个按钮可以在一次单击时执行两个任务 [英] can a button perform two tasks on a single click

查看:62
本文介绍了一个按钮可以在一次单击时执行两个任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开展一个项目,我们必须通过点击一个按钮将日期和时间发送到数据库中。我们必须点击同一个按钮进入下一个html页面。



但这两项任务应该只需点击一下就可以了。



这可能吗?如果是,请帮助我。

解决方案

是的。尽可能多的...

< button onclick =   do_one(); do_two(); do_more(); /> 






为了调用两个函数,在函数调用结束时添加分号(;)并添加新的函数调用。像

< button onclick =one(); two();/> 



请参阅下面的内容。

http://www.sitepoint.com/web-foundations/onclick-html-attribute/ [ ^ ]


你可以尝试以下代码段,



 <  !DOCTYPE     htm l  >  
< html >
< head >
< meta charset = utf-8 / >
< title > JS Bin < / title >
< / head >
< body >
< 输入 id = btn type = 按钮 value = 点击 onclick = event1(),event2() / >
< / body >
< / html >

< script type = text / javascript >
function event1(){
//事件的定义-1
}

函数event2(){
//事件的定义 - 2
}
< / script >


We are working on a project where we have to send date and time into database by clicking a button and We have to go to next html page on clicking the same button.

But these two tasks should happen on a single click.

Can this be possible?? If it is, Please help me.

解决方案

Yes. As many as you want...

<button onclick="do_one(); do_two(); do_more();" />


Hi,

In order to call two functions add semi-colons (";") to the end of the function call and add new function calls .Something like

<button onclick="one();two();"/>


Please refer below also.
http://www.sitepoint.com/web-foundations/onclick-html-attribute/[^]


You can try out the following code segment,

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <input id ="btn" type="button" value="click" onclick="event1(), event2()"/>
</body>
</html>

<script type="text/javascript">
function event1() {
  //defination of the event-1
}

function event2() {
  //defination of the event-2
}
</script>


这篇关于一个按钮可以在一次单击时执行两个任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆