单击按钮不转到JS功能
onClick for button not going to JS function
我正在尝试使用 onClick
定向到 JS 函数,但似乎没有任何效果,我已经尝试过:
.HTML:
<button type="button" id="deleteBtn" onClick="toDelete();">Delete Event</button>
.JS:
document.getElementById("deleteBtn").onclick = function() {toDelete()}
.JS:
document.getElementById("deleteBtn").addEventListener("click", toDelete);
这是我的函数:
function toDelete()
{
var answer = confirm("Are you sure you want to delete this event?'nPress OK to confirm deletion or CANCEL otherwise");
if (answer)
{
alert("The event has been deleted!");
<?php
echo "<form id='deleteForm' name='deleteForm' method='post' action='redirected/deleteRecord.php'>";
echo "<input name='EVENT_ID' type='hidden' value='{$EVENT_ID}'>";
echo "<input name='eventName' type='hidden' value='{$eventName}'>";
echo "<input name='addressLine_1' type='hidden' value='{$addressLine_1}'>";
echo "<input name='addressLine_2' type='hidden' value='{$addressLine_2}'>";
echo "<input name='townCity' type='hidden' value='{$townCity}'>";
echo "<input name='postcode' type='hidden' value='{$postcode}'>";
echo "<input name='description' type='hidden' value='{$description}'>";
echo "<input name='cost' type='hidden' value='{$cost}'>";
echo "<input name='eventDate' type='hidden' value={$eventDate}'>";
echo "</form>";
?>
document.getElementById('deleteForm').submit();
}
else
location.replace("events.php");
}
我编写了一个带有一个隐藏输入字段的示例代码片段(您可以在那里添加 php 代码)。当<form>
元素移动到<script>
标签之外时,它起作用。
function toDelete() {
var answer = confirm("Are you sure you want to delete this event?'nPress OK to confirm deletion or CANCEL otherwise");
if (answer) {
alert("The event has been deleted!");
document.getElementById('deleteForm').submit();
}
else
location.replace("events.php");
}
function updateConfirm() {
alert("Event has been updated!");
}
<button type="button" id="deleteBtn" onclick="javascript:toDelete();">Delete Event</button>
<form id='deleteForm' name='deleteForm' method='post' action='redirected/deleteRecord.php'>
<input name='EVENT_ID' type='hidden' value='testid'>
</form>
尝试使用 setTimeout
document.getElementById("deleteBtn").onclick = function() {setTimeout(function(){toDelete()},500);}
相关文章:
- 使用视频js功能触发多个视频
- 对页面上的所有ID执行JS功能
- Odoo扩展网站销售JS功能
- 通过自定义JS功能激活Sencha Touch选项卡
- 在 IOS 中实现 JS 功能
- 通过JS功能在中继器中启用文本框
- 带有文本显示js功能的图像映射 - 某些部分不显示
- 无法在跨域环境中访问JS功能
- 单击按钮不转到JS功能
- iPad上的悬停js功能无法切换
- TinyMCE将JS功能扩展到页面高度,就像在wordpress中一样
- 是否有JS功能可以使Brightcove智能播放器视频开始播放
- 通过切换文件覆盖JS功能
- 音轨 JS 功能无法播放或暂停音频
- 我需要有人来ELI5这个Skrollr.js功能
- 在JS功能中使用php变量
- 点击DIV或A标签激活JS功能
- 从 web JS 功能在 fb-messenger:// url 方案上共享私人消息中的链接
- 创建一个封装角度 js 功能的实用程序模块
- Youtube搜索js功能