我是php和JS的新手,我有一段代码一直被困在上面,无法工作:
我的something.php只有$variable= $_POST['SUBMIT']
echo $variable
<?php
$list=$_POST['added'];
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type='text/javascript' src='http://code.jquery.com/jquery-1.6.js'></script>
<link rel="stylesheet" type="text/css" href="/css/normalize.css">
<link rel="stylesheet" type="text/css" href="/css/result-light.css">
<style type='text/css'>
#display{
width: 500px;
height: 250px;
overflow: scroll;
background-color:white;
}
#display div {
clear: both;
}
#display div span{
float: left;
padding: 10px;
}
.edit {
color: blue;
}
.delete {
color: red;
}
body {background-color:orange;}
p {color:orange;
size=3;
}
body {
background-image: url("http://dev.icalapp.rogersdigitalmedia.com.rogers-test.com/rogers_blackberry_8900.jpg");
background-position: 50% 50%;
background-repeat: repeat;
}
</style>
<script type='text/javascript'>
//<![CDATA[
$(window).load(function(){
$('#add').click(function() {
this.innerHTML = 'Add';
var input = $('#addInput');
var display = $('#display');
var form = $('#addForm');
if ($.trim(input.val()).length > 0) { //is there input?
var div = $('<div>').append($('<span>', {
text: input.val()
}), $('<span>', {
text: 'delete',
class: 'delete'
}), $('<span>', {
text: 'edit',
class: 'edit'
}))
display.append(div);
form.append($('<input>', {
value: input.val(),
type: 'hidden',
name: 'added[]'
}));
input.val('');
}
})
$('.edit').live('click', function(){
$('#add').html('Edit');
var input = $('#addInput');
var index = $(this).parent().index() + 1;
input.val($(this).parent().children().get(0).innerHTML); //show value
$(this).parent().remove(); //remove it from the list
$('#addForm').children().eq(index).remove();
});
$('.delete').live('click', function(){
var index = $(this).parent().index() + 1;
$('#addForm').children().eq(index).remove();
$(this).parent().remove(); //remove it from the list
});
});
//]]>
</script>
<title>Admin Phone Setup</title>
</head>
<body>
<STYLE>H2 {FONT-SIZE: 21pt; COLOR: #ff3399}; </STYLE>
<CENTER>
<H2>Twilio Admin Setup</H2>
</CENTER>
<p id="demo">Enter Phone Numbers</p>
<input id="addInput"/> <button id="add">Add</button>
<div id='display'></div>
<form action="something.php" id="addForm">
<input type="submit" value="SUBMIT"/>
</form>
</body>
</html>
我想做的是,一旦一个人在列表中添加了一堆数字并点击提交,它就会将这些值发送到something.php,这样我就可以使用这些值。。。我真的被卡住了,不知道自己做错了什么。。。我想这可能是变量或我的显示列表有问题。
1)您的按钮未命名。要获得按钮值,您必须提供名称属性,例如
<input type="submit" name="mysubmitbutton" value="SUBMIT" />
2) 在你的something.php中,你使用POST数组,但你的表单是用GET数据提交的,因为你的表单标签上没有"method"属性。此外,您似乎试图通过使用buttons值作为索引来访问它的值(这不是word;))。您可以选择(命名按钮后)a) 在PHP脚本中使用$_GET['mysubmitbutton']b) 将表单标签更改为
<form ... method="post" ... >
并使用$_POST['mysubmitbutton']。