我使用 js 将变量分配给隐藏表单的值。但是,当我尝试在 php 中访问它时,什么也没有出现。我知道 javascript 正在正确地将值添加到表单中,但是由于某种原因 php 无法得到它。继承人的代码:
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="textualizer.min.js"></script>
</head>
<style type="text/css">
#txtlzr{color:#585856; font-size:50px; width:1200px; height:100px;
margin-left:10%;
margin-top:80px;
font-family:"futura";
position: fixed;
}
</style>
<body>
<div id="txtlzr"></div>
<form name="kwoteForm" action="main.php" method="post"/>
<input type="hidden" id="kwoteString" name="kwoteString" value="bob" />
<input class="kwote" type="text" maxlength="40" id="kwote"placeholder="Enter a something here."/>
<input class="name" type="text" maxlength="17" id="name" placeholder="Enter your name."/>
<input class="post" type="submit" value="Add comment" onclick="add_comment();" />
</form>
<script language="javascript">
var COMMENTS_FOR_DISPLAY = new Array('OOOOOOO ITS WORKING : NICK');
// Adds a new comment, name pair to the Array feeding textualizer.
function add_comment() {
// Retrieve values and add them to Array.
var new_comment = $('#kwote').val();
var new_name = $('#name').val();
COMMENTS_FOR_DISPLAY.push(new_comment + ': ' + new_name);
// Reset <input> fields.
$('#kwote').val('');
$('#name').val('');
//Take comment array and put it into a string.
var arrayAsString = JSON.stringify(COMMENTS_FOR_DISPLAY);
//Assign value of the string to a hidden form.
document.getElementById("kwoteString").value = arrayAsString;
//checks output.
alert(document.kwoteForm.kwoteString.value);
}
$(document).ready(function() {
var txt = $('#txtlzr'); // The container in which to render the list
var options = {
duration: 5, // Time (ms) each blurb will remain on screen
rearrangeDuration: 5, // Time a character takes to reach its position
effect: 'random', // Animation effect the characters use to appear
centered: true // Centers the text relative to its container
}
txt.textualizer(COMMENTS_FOR_DISPLAY); // textualize it!
txt.textualizer('start'); // start
});
</script>
</body>
</html>
PHP:
<?php
$saveKwote = $_POST["kwoteString"];
echo saveKwote;
?>
出于某种原因,没有任何回应!