我试图弄清楚为什么在提交表单后没有调用此函数。提交表单时,“checkForm()”JS 函数可以正常工作,但我似乎无法让 checkDates() 函数正常工作。我尝试将其移至 PHP 代码上方,但未显示任何警报消息。非常感谢任何帮助,谢谢!
这是我的文件的伪代码版本:
<?php
if(isset($_POST['next'])){
// Some PHP code
echo "<script> checkDates(); </script>";
}
?>
<form name="form1" id="form1" method="post" action="<?php print $thispage;?>" onsubmit="return checkForm()">
// Some HTML code
</form>
<script>
var isDateTimeValid = true;
function checkDates() {
alert("Hello");
isDateTimeValid = false;
}
function checkForm () {
if (isDateTimeValid == true) {
return true;
}
else {
return false;
}
}
</script>
Run Code Online (Sandbox Code Playgroud) 试图找出我的代码中缺少的内容,该代码应该将链表 2 合并到链表 1 的末尾。现在它只是获取第二个列表中的最后一个元素并返回它。
我试图使用的逻辑是沿着第一个列表 (L1) 向下走,并将这些元素逐个添加到 new_list,然后在到达 L1 末尾后对第二个列表 (L2) 执行相同的操作。我还试图避免修改 L1 或 L2,这就是我创建 new_list 的原因。
任何帮助将不胜感激。
public NodeList(int item, NodeList next) {
this.item = item;
this.next = next;
}
public static NodeList merge(NodeList l1, NodeList l2) {
NodeList new_list = new NodeList(l1.item, l1.next);
NodeList new_list2 = new NodeList(l2.item, l2.next);
while (true) {
if (new_list.next == null) {
if (new_list2.next == null) {
return new_list;
}
else {
new_list.next = new NodeList(new_list2.next.item, new_list2.next.next);
new_list2 = new_list2.next;
}
} …
Run Code Online (Sandbox Code Playgroud)