gpt4 book ai didi

javascript - js提交后检查按钮是否被按下

转载 作者:行者123 更新时间:2023-11-30 16:41:27 26 4
gpt4 key购买 nike

在我使用 javascript 提交表单后,我正在尝试检查是否按下了表单类型按钮:

<script>
function DeleteIt(string){
var pattern = string.indexOf('_');
var prof_nr = string.substr(pattern+1);
var delete = confirm("Want to delete it?");

if( delete == true ){
document.forms['form'].submit();
}else{
alert('Cancel');
}
}
</script>

<form method="POST" name="form">
<input type="button" name="delete" value="Delete" id="prof_'.$row['code'].'" onclick="DeleteIt(this.id);">
</form>

if(isset($_POST['delete'])){
echo 'Pressed';
}

但是虽然已经按下了,但并没有遇到这种情况。我不能使用提交类型,因为我已经在表单中有一个用于搜索字段的提交类型。每当我键入内容并按回车键时,它都会触发该功能,这就是我使用按钮的原因。

最佳答案

您在代码中使用了很多语言关键字作为变量名,例如 deletestring

You can not use reserved words of a programming language as your variable names.

这是工作代码-

<script type="text/javascript">
function DeleteIt(string1){
var pattern = string1.indexOf('_');
var prof_nr = string1.substr(pattern+1);
var delete1 = confirm("Want to delete it?");

if( delete1 == true ){
document.forms['form'].submit();
}else{
alert('Cancel');
}
}
</script>

<form method="POST" name="form">
<button name="delete" id="prof_'.$row['code'].'" onclick="DeleteIt(this.id);">delete</button>
</form>

<?php
if(isset($_POST['delete'])){
echo 'Pressed';
}

关于javascript - js提交后检查按钮是否被按下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31917551/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com