答案 0 :(得分:0)
使用PHP&您可以使用Javascript:
<html>
<body>
<form id="example" name="example">
<select name="myName" id="myID" onchange="updateText()">
<?php
$tip_stingu = "G1-11, G2-21, P2-50, P4-20, P100-2,";
$pieces = explode(', ', $tip_sting);
$piece1 = explode('-', $pieces[0])[1];
foreach($pieces as $piece) {
$tip_stinga = explode("-", $piece);
echo ('<option value="'.$tip_stinga[1].'">'.$tip_stinga[0].'</option>');
}
echo '</select><input type="text" value="'.$piece1.'" id="quantity" /><br />'
?>
</form>
<script>
function updateText() {
document.getElementById("quantity").value = document.getElementById("myID").value;
}
</script>
</body>
</html>
您的示例末尾还有一个尾随逗号,如果这是您可以使用的问题:
echo ('<option value="'.rtrim($tip_stinga[1], ',').'">'.$tip_stinga[0].'</option>');
而不是:
echo ('<option value="'.$tip_stinga[1].'">'.$tip_stinga[0].'</option>');
答案 1 :(得分:0)
你需要这样的东西吗?
<?php
$items = "G1-11, G2-21, P2-50, P4-20, P100-2";
$pieces = explode(",", $items);
echo ("<select>");
foreach ($pieces as $piece) {
$tip_stinga = explode("-", $piece);
echo ('<option value="'.$tip_stinga[1].'">'.$tip_stinga[0].'</option>');
}
echo ("</select>");
?>