gpt4 book ai didi

JavaScript:无法从表单获取值

转载 作者:行者123 更新时间:2023-12-01 01:48:27 26 4
gpt4 key购买 nike

我试图让javascript从文本框中获取值并提醒它,但它总是弹出“未定义”。我尝试从组合框中获取所选项目的值,但仍然显示未定义。当我尝试在简单的网页中使用 js 时,它有效。也许我的代码有问题。

注意:我希望在单击“计划”按钮时弹出该值。 js将从txtbox中获取值和选定的时间值。但事实并非如此..

代码:index.php

    <!DOCTYPE html>
<html lang='en'>
<head>
<title>Pinterest Grabber</title>
<style>
html, body{
width: 100%;
background-color: #DADADA;
color: black;
font-family: georgia, sans-serif, arial;
}

.container{
background-color: white;
width: 95%;
margin: auto;
padding: 10px;
box-shadow: 0px 5px 10px #333;
border: none;
border-radius: 2px;
}

.setupForm{
background-color: #ff9;
margin: 10px;
}

.pinterestForm{
background-color: #ff9;
margin-top: 2%;
}

.formTxtbox{
margin-bottom: 1%;
border: none;
width: 75%;
text-align: center;
font-size: 17px;
height: 30px;
background-color: white;
color: black;
transition-property: box-shadow;
transition-duration: 0.3s;
}

.formTxtbox:hover{
box-shadow: 0px 0px 10px #cab;
}

.formButton{
margin-bottom: 1%;
border: none;
background-color: royalblue;
color: white;
padding: 7px 35px;
font-size: 17px;
transition-property: background-color, box-shadow, color;
transition-duration: 0.3s;
}

.formButton:hover{
background-color: lime;
box-shadow: 5px 5px 5px black;
color: black;
cursor: pointer;
}

.txtboxSmall{
margin-bottom: 1%;
border: none;
width: 50%;
text-align: center;
font-size: 17px;
height: 30px;
background-color: white;
color: black;
transition-property: box-shadow;
transition-duration: 0.3s;
}

.txtboxSmall:hover{
box-shadow: 0px 0px 10px #cab;
}

.scheduleContainer{
background-color: #FF9800;
}

#scheduleOptions{
border: none;
width: 5%;
height: 30px;
}

</style>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('.setupForm').hide();

$("#btnSettingsToggle").click(function(){
$(".setupForm").toggle('fast');
});

});

// js
var interval;
var time = document.getElementById('txtScheduleInterval').value;
var timeOptions = document.getElementById("scheduleOptions").value;

function schedule()
{
alert(time);
}

</script>
</head>
<body>
<div class="container">
<header>
<h1 align="center">Pinterest Grabber</h1>
</header>

<button class="formButton" id="btnSettingsToggle">Settings</button>

<center>
<form action="setup.php" method="post" class="setupForm">
<h2>Settings</h2>
<input class="formTxtbox" type="text" name="condapath" placeholder="Your Anaconda Path"><br>
<input class="formTxtbox" type="text" name="envname" placeholder="Enviroment Name To Activate"><br>
<input class="formButton" type="submit" value="Save Settings">
</form>
</center>
<?php
$settings = file('settings.txt', FILE_SKIP_EMPTY_LINES);
echo "<b>Working Path:</b> " . $settings[0] . '<br>';
echo "<b>Working Environment:</b> " . $settings[1] . '<br>';
?>

<center>
<form action="pinterest.php" method="post" class="pinterestForm">
<h2 align="left" style="margin-top:1%;margin-left:1%;">Pinterest Single</h2>
<input class="formTxtbox" type="text" name="singleSearchTerm" placeholder="Enter Search Term (EX: old kl)"><br>
<input class="formTxtbox" type="text" name="singleFilename" placeholder="Enter Filename (EX: data.csv)"><br>
<input class="formButton" type="submit" value="Start" name="btnPinSingle">
</form>

<form action="#" method="post" class="pinterestForm">
<h2 align="left" style="margin-top:1%;margin-left:1%;">Pinterest Bulk</h2>
<input class="formTxtbox" type="text" name="listPath" placeholder="Enter List Path (EX: c:\folder\list.txt)"><br>
<input class="txtboxSmall" type="text" id="txtScheduleInterval" placeholder="Enter Schedule Time">
<select id="scheduleOptions">
<option value="secs">Seconds</option>
<option value="mins">Minutes</option>
<option value="hrs">Hours</option>
</select>
<br>
<button type="button" class="formButton" onclick="schedule(); return false;">Schedule</button>
<input class="formButton" type="submit" value="Start Now" name="btnPinBulk">
</form>
</center>

</div>
</body>
</html>

以下是 JSFiddle 上的托管代码:https://jsfiddle.net/Lnt0crs8/1/

如有任何帮助,我们将不胜感激。谢谢。

最佳答案

在单击函数调用中获取文本框值并尝试

function schedule()
{
var time = document.getElementById('txtScheduleInterval').value;
alert(time);
}

关于JavaScript:无法从表单获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51780746/

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