目标HTML选项标签,而不是PHP中的值?
我试图在PHP页面中将选项标签作为目标,而不是它的值 我知道PHP是服务器端的,可能很难确定选项标签的目标,但是有解决方法吗 我使用的代码如下:目标HTML选项标签,而不是PHP中的值?,php,html,Php,Html,我试图在PHP页面中将选项标签作为目标,而不是它的值 我知道PHP是服务器端的,可能很难确定选项标签的目标,但是有解决方法吗 我使用的代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href=
"css/mainstyle_css.css" />
<meta http-equiv="Content-Type" content=
"text/html; charset=utf-8" />
<title>
title
</title>
</head>
<body>
<form method="post" action="">
<select name="myList" id="myList" class="myList">
<optgroup label="list 1">
<option value="music/one" label="techno">techno</option>
<option value="music/two" label="rock">rock</option>
</optgroup>
</select>
<input type="submit" name="submit" id="submit" class="submit" value="Search"/>
</form>
<?php echo $myList; ?>
</body>
</html>
标题
技术
岩石
通过上面的代码,我在php页面上得到了music/one和music/two。我需要做的是呼应他们的标签,即“技术”和“摇滚”
有人能帮我一下吗?你可以这样做:
<?php
$options = array();
$options["music/one"] = "techno";
$options["music/two"] = "rock";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="css/mainstyle_css.css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>title</title>
</head>
<body>
<form method="post" action="">
<select name="myList" id="myList" class="myList">
<optgroup label="list 1">
<?php
foreach($options as $key => $value)
{
echo '<option value="'. $key .'" label="'. $value .'">'.$value.'</option>';
}
?>
</optgroup>
</select>
<input type="submit" name="submit" id="submit" class="submit" value="Search"/>
</form>
<?php echo $options[$_POST['myList']]; ?>
</body>
</html>
标题
试试这个:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href=
"css/mainstyle_css.css" />
<meta http-equiv="Content-Type" content=
"text/html; charset=utf-8" />
<title>
title
</title>
</head>
<body>
<form method="post" action="a.php">
<select name="myList" id="myList" class="myList">
<optgroup label="list 1">
<?php
foreach($options as $key => $value)
{
echo "<option value='{$key}' label='{$value}'>{$value}</option>"; // this will fill all your values in option field via loop
}
?>
<option value="music/one" label="techno">techno</option> // you can also do it this way manually as u did.
<option value="music/two" label="rock">rock</option>
</optgroup>
</select>
<input type="submit" name="submit" id="submit" class="submit" value="Search"/>
</form>
</body>
</html>
// below codeshould be in a.php
<?php if(isset($_POST['submit']))
{
echo $_POST['myList'];
}
?>
标题
您可以更改如下选项:techno
为什么要在服务器上使用PHP解析HTML?这毫无意义。很抱歉,这是离题,但为什么您仍在使用该doctype?我以为我们都换了。。“你知道,为了一致性,”阿卡姆,不,我不能那样做。这些值应该保持原样。我显然遗漏了一些东西。你在哪里设置$myList?好吧,这在某种程度上是可行的。但是如果页面上有100个选项呢?我是否必须添加$options[“music/three”]=“somename”$选项[“音乐/four”]=“somename”;每一个人?还是有其他方法可以做到这一点?