cell10.innerHTML = "<button onclick='confirmRow(this)'>确认</button>" 修改代码 一次点击可以调用2个函数
时间: 2023-08-31 07:20:10 浏览: 51
### 回答1:
你可以在 `onclick` 属性中调用两个函数,以分号 `;` 分隔开即可,例如:
```
cell10.innerHTML = "<button onclick='confirmRow(this); anotherFunction()'>确认</button>"
```
这样点击按钮时,就会依次调用 `confirmRow()` 和 `anotherFunction()` 两个函数。当然,这两个函数都需要定义好并且可以被访问到。
### 回答2:
要实现一次点击调用两个函数的功能,可以使用JavaScript中的事件监听器和函数串联的方式来实现。
首先,在HTML代码中,我们将要修改的一行的相关单元格绑定一个点击事件,更改为:
```
cell10.innerHTML = "<button onclick='callTwoFunctions(this)'>确认</button>";
```
接下来,在JavaScript代码中,我们定义一个名为callTwoFunctions的函数,将其作为点击事件的处理函数:
```javascript
function callTwoFunctions(button) {
confirmRow(button);
yourSecondFunction(button);
}
```
在这个函数中,我们首先调用confirmRow函数,并将按钮元素作为参数传递给它,然后调用yourSecondFunction函数,并将按钮元素作为参数传递给它。
这样,在一次点击按钮的时候,就会先调用confirmRow函数,然后再调用yourSecondFunction函数,实现了一次点击调用两个函数的效果。
请注意,你需要将yourSecondFunction替换为你自己定义的第二个函数的名称。同时,确认confirmRow函数和yourSecondFunction函数都已经在你的代码中定义和实现。
### 回答3:
要实现一次点击调用两个函数的功能,可以通过调用匿名函数来实现。具体代码如下:
```
cell10.innerHTML = "<button onclick='(function(){confirmRow(this); anotherFunction();})()'>确认</button>";
```
以上代码将原有的 `confirmRow(this)` 修改为 `(function(){confirmRow(this); anotherFunction();})()`,即调用了一个匿名函数。在该匿名函数中,先调用 `confirmRow(this)`,然后调用 `anotherFunction()`,这样就可以在一次点击按钮时同时调用两个函数了。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
<legend class="field_title"> 增加行 </legend> 操作 提单号/运单号 一程日期 二程日期 预计到货日期 海船公司 放箱日期 放箱单上传 <input type="button" name="comment" value="删除"> <input type="text" name="comment"> <input type="date" name="date1"> <input type="date" name="date2"> <input type="date" name="date3"> <input type="text" name="commen1t"> <input type="date" name="date4"> <input type="file" name="attachment"> 新增和删除
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)