<form target="sys" id="form50" method="post" action="/cgi-bin/reboot"> <input type="submit" name="reboot" id="reboot" value="重启" style="border:none;background:none;cursor:pointer;outline:none;"/> </form>将里面的form50封装到 函数function confirmRestart(formId) { if (confirm('需重启才能生效,是否立即重启?')) { document.getElementById('form50').submit(); } else { document.getElementById(formId).submit(); } }中
时间: 2023-07-06 15:17:21 浏览: 43
可以将以下代码添加到页面的 `<script>` 标签中或者外部的 JavaScript 文件中:
```
function confirmRestart(formId) {
if (confirm('需重启才能生效,是否立即重启?')) {
document.getElementById('form50').submit();
} else {
document.getElementById(formId).submit();
}
}
```
然后在需要调用的地方,使用以下代码调用该函数:
```
confirmRestart('form50');
```
这将触发一个 confirm 对话框,如果用户确认,则会提交 id 为 `form50` 的表单,否则会提交传递进来的表单 ID。
相关问题
在<td ><form target="ip" id="form28" name="form4" method="post" action="/cgi-bin/vgaic.cgi"> <input type="text" name="ip" id="ip" size="16" /> <label for="name1_submit"></label> <input type="submit" name="name1_submit" id="name1_submit" onclick="if(confirm('需重启才能生效,是否立即重启?点确定立即重启')) {} else{return false;}" value="设置" /> <label for="label50"></label> <input type="reset" name="name_abord16" id="label50" value="清除" /> </form></td>的弹窗中增加一个重启按钮 <td ><form target="sys" id="form20" method="post" action="/cgi-bin/reboot"> <input type="submit" name="reboot" id="reboot" value="重启" /> </form>
在这段代码中,可以在`<td>`标签内添加一个新的`<form>`标签,用于提交重启请求。具体代码如下:
```
<td>
<form target="ip" id="form28" name="form4" method="post" action="/cgi-bin/vgaic.cgi">
<input type="text" name="ip" id="ip" size="16" />
<label for="name1_submit"></label>
<input type="submit" name="name1_submit" id="name1_submit" onclick="if(confirm('需重启才能生效,是否立即重启?点确定立即重启')) {} else {return false;}" value="设置" />
<label for="label50"></label>
<input type="reset" name="name_abord16" id="label50" value="清除" />
</form>
<form target="sys" id="form29" method="post" action="/cgi-bin/reboot">
<input type="submit" name="reboot" id="reboot" value="重启" />
</form>
</td>
```
这段代码中,我们新增了一个`<form>`标签,`target`属性设置为`sys`,用于提交重启请求。按钮的`name`属性设置为`reboot`,当用户点击该按钮时,会向服务器发送一个重启请求。
在<td ><form target="ip" id="form28" name="form4" method="post" action="/cgi-bin/vgaic.cgi"> <input type="text" name="ip" id="ip" size="16" /> <label for="name1_submit"></label> <input type="submit" name="name1_submit" id="name1_submit" onclick="if(confirm('需重启才能生效,是否立即重启?点确定立即重启')) {} else{return false;}" value="设置" /> <label for="label50"></label> <input type="reset" name="name_abord16" id="label50" value="清除" /> </form></td>的onclick弹窗中增加一个已有的确定重启的按钮 <td ><form target="sys" id="form20" method="post" action="/cgi-bin/reboot"> <input type="submit" name="reboot" id="reboot" value="重启" /> </form>
如果您想在弹窗中添加一个已有的确定重启按钮,可以修改原有的onclick事件,将原有的确定按钮和弹窗合并。具体代码如下:
```
<td>
<form target="ip" id="form28" name="form4" method="post" action="/cgi-bin/vgaic.cgi">
<input type="text" name="ip" id="ip" size="16" />
<label for="name1_submit"></label>
<input type="submit" name="name1_submit" id="name1_submit" onclick="if(confirm('需重启才能生效,是否立即重启?')) {document.getElementById('form29').submit();} else {return false;}" value="设置" />
<label for="label50"></label>
<input type="reset" name="name_abord16" id="label50" value="清除" />
</form>
<form target="sys" id="form29" method="post" action="/cgi-bin/reboot">
<input type="submit" name="reboot" id="reboot" value="重启" />
</form>
</td>
```
在这段代码中,我们修改了原来的onclick事件,将原来的弹窗和确定按钮合并为一个操作。当用户点击设置按钮时,会弹出一个确认框,如果用户点击“确定”按钮,则会直接提交重启请求,否则不进行任何操作。
相关推荐
![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)
![](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)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)