<div> <button onclick="showAlert()">开始</button> </div> <script> function showAlert() { alert("刷新"); } </script>设置这个弹窗显示2秒
时间: 2023-12-14 07:39:13 浏览: 25
可以使用setTimeout函数来实现弹窗显示2秒的效果,具体代码如下:
```
<div>
<button onclick="showAlert()">开始</button>
</div>
<script>
function showAlert() {
alert("刷新");
setTimeout(function(){alert("2秒后自动关闭");}, 2000);
}
</script>
```
在弹窗显示后,使用setTimeout函数再次弹出一个提示框,等待2秒后自动关闭。
相关问题
<div> <button>开始</button> </div> <script> alert("刷新") </script>添加一下代码,点击按钮再弹窗
可以尝试以下代码:
```
<div>
<button onclick="showAlert()">开始</button>
</div>
<script>
function showAlert() {
alert("刷新");
}
</script>
```
当点击按钮时,会触发 `showAlert()` 函数,该函数会弹出一个包含 "刷新" 的提示框。
function generateReport() { try { var getUrl = window.location; var baseUrl = getUrl.protocol + "//" + getUrl.host + "/"; var url = baseUrl + 'polarion/ImpactAnalysisTree/ImpactAnalysisTree?projectId=' + projectId; var parameters = ""; var Id = false; var title = false; var workItemId = document.forms["tracegraph"]["itemId"]; if (workItemId != null) { if (!workItemId.value.trim().length == 0) { parameters = '&op=search&workItemId=' + workItemId.value; Id = true; } } if (!Id) { $(".widget-errors").text("Enter a valid Work Item ID /Title to generate traceability report.").show(); return false; } // AJAX 异步请求 $.ajax({ url: url + parameters, method: 'POST', success: function(response) { Data = JSON.parse(response); }, error: function(error) { console.log(error); alert(error); } }); } catch (e) { console.log(e); alert(e); } return false; } 根据返回的值重新渲染下面代码 <FORM id="tracegraph"> <br /> <form name="tracegraph"> <div id="inputDiv"> <table> <tr> <td valign="center" align="right">Work Item ID </td> <td> <div class="autocomplete"> <input id="itemId" type="text" name="itemId" autocomplete="off" placeholder="Work Item ID" style="width: 225px;"> </div> </td> </tr> </table> </div> </form> <table> <tr> <td> <button onclick="generateReport()" class="reportbutton" style="margin-left: 18px;" VALIGN=MIDDLE ALIGN=CENTER> Display Report</button> </td> </tr> </table> <br> <div class="widget-errors"></div> <div id="mainSVG"></div>
根据返回的值重新渲染下面代码:
```html
<FORM id="tracegraph">
<br />
<form name="tracegraph">
<div id="inputDiv">
<table>
<tr>
<td valign="center" align="right">Work Item ID </td>
<td>
<div class="autocomplete">
<input id="itemId" type="text" name="itemId" autocomplete="off" placeholder="Work Item ID" style="width: 225px;">
</div>
</td>
</tr>
</table>
</div>
</form>
<table>
<tr>
<td>
<button onclick="generateReport()" class="reportbutton" style="margin-left: 18px;" VALIGN=MIDDLE ALIGN=CENTER>Display Report</button>
</td>
</tr>
</table>
<br>
<div class="widget-errors"></div>
<div id="mainSVG"></div>
</FORM>
```