我正在尝试通过提交表单更改网址路径...
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<?php include 'file.php'; ?>
<form action=<?php action(); ?> method="post">
<fieldset>
<legend>Choose ID by select tag</legend>
<label>ID:</label>
<select name="id" onchange="this.form.submit()">
<?php option(); ?>
</select>
<label><?php selcet(); ?></label>
</fieldset>
</form>
</body>
</html>
<?php
function action() {
$value = $_SERVER['PHP_SELF'];
if (isset($_POST['id'])) {
$value .= '?id=' . $_POST['id'];
}
echo $value;
}
function option() {
$count = 3;
for ($i = 1; $i <= $count; $i++) {
$value = 1;
if (isset($_POST['id'])) {
$value = $_POST['id'];
}
if ($i == $value) {
echo '<option value="' . $i . '" selected>' . $i . '</option>';
}
else {
echo '<option value="' . $i . '">' . $i . '</option>';
}
}
}
function selcet() {
$value = 1;
if (isset($_POST['id'])) {
$value = $_POST['id'];
}
echo 'Option ' . $value . ' selected.';
}
?>
action()函数不能正常工作,我得错了ID,我想得到?id = 2而选择'2'。
是的,有人能帮帮我吗?谢谢! :)答案 0 :(得分:0)
要达到您的原始要求:
index.php
您需要使用GET而不是POST才能获得最简单,最快速的结果。
<?php include 'file.php'; ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<form action="<?php echo active(); ?>" method="GET">
<fieldset>
<legend>Choose ID by select tag</legend>
<label>ID:</label>
<select name="id" onchange="this.form.submit()">
<?php echo option(); ?>
</select>
<label><?php echo select(); ?></label>
</fieldset>
</form>
</body>
</html>
file.php
<?php
function active() {
$value = $_SERVER['PHP_SELF'];
if (isset($_GET['id'])) {
$value .= '?id=' . $_GET['id'];
}
return $value;
}
function option() {
$count = 3;
for ($i = 1; $i <= $count; $i++) {
$value = 1;
if (isset($_GET['id'])) {
$value = $_GET['id'];
}
if ($i == $value) {
echo '<option value="' . $i . '" selected>' . $i . '</option>';
}
else {
echo '<option value="' . $i . '">' . $i . '</option>';
}
}
}
function select() {
$value = 1;
if (isset($_GET['id'])) {
$value = $_GET['id'];
}
return 'Option ' . $value . ' selected.';
}
?>
XDocument xdoc = XDocument.Load(@"C:\Project\conf\config.xml");
string sSetting = "KNF";
string sSetting = "KNR";
var result = xdoc.Descendants("Felder").Descendants()
.Where(x=>x.Name == sSetting)
.Select(x=>new {
Length = x.Element("Length").Value,
Format = x.Element("Format").Value
});