如何在按钮单击时执行两个操作

时间:2014-02-06 10:07:56

标签: php codeigniter

我有一个页面,其中包含一些输入字段和一个表格以及三个按钮播放,暂停,停止。我只想在按下播放按钮时刷新表格部分。我希望播放按钮执行两个操作,一个是运行更新查询并仅重新加载页面。当我点击暂停按钮时,我想停止重新加载表。当我按下停止按钮时,我希望它运行一个udate查询。我正在使用codeigniter,MVC架构。这是我尝试过的和我的观看页面。

<meta http-equiv="refresh" content="300">   
<input type="text" size="7" id="IC" name="IC" value="<?php echo set_value('IC',$IC); ?>" />
<input type="text" size="7" id="ID" name="ID" value="<?php echo set_value('ID',$ID); ?>" />
<button type="button" style="width:100px;">PLAY</button>
<button type="button" style="width:100px;">PAUSE</button>
<button type="button" style="width:100px;">STOP</button>
<table>
<tr>
<th> blah </th>
<th> blah </th>
<th> blah </th>
</tr>
//do some  code
</table>    

3 个答案:

答案 0 :(得分:1)

您可以通过单击按钮一次调用两个js函数。像一种方式..

function jsfun1()
{
   //do the action here
}

function jsfun2()
{
   //do the action here
}

call both on onclick

<button type="button" style="width:100px;"  onclick="jsfun1(),jsfun2()">play</button>

答案 1 :(得分:1)

用javascript做。

只需制作2个函数并在Button标签中使用onclick-action。 onclick="playButton0(),playButton1()"

答案 2 :(得分:1)

您可以使用jQuery框架来完成所有这些工作。

每个按钮的盲.click功能,并使用$.ajax功能

执行操作

使用ajax功能,您可以将值发布到您想要的控制器,并执行查询或您想要的任何内容。

更多信息:

http://api.jquery.com/click/

http://api.jquery.com/jquery.ajax/