将单选/复选框更改为下拉框,对 PHP 编码进行最小的更改?
解决方案:感谢@Guarav 的建议,我受到了启发并最终提出了解决方案,请告诉我你们对我的解决方案的看法以及我可以进一步改进的任何方法。是的,这是一个挑战。我打赌你不能。
<?php
function selectLang($a,$b,$c,$d,$e){
echo "<div id='menu2' style='width:250px; margin-left:-40px;'> <ul class='double'>
<li style='background:#333333; color:white;'>Demonstration Play Feature</li>";
echo "<form method='post' action=''>";
echo "<li><select name='languages[]'>";
while(list(,$values1) = each($c) AND list(,$list) = each($b) AND list(,$list2) = each($e)) {
echo "<option name='languages[]' value='$values1' />" . $list . "</option>";
echo "<option name='languages[]' value='$values1' />" . $list2 . "</option>";
}
echo "</select>";
echo "<input type='submit' value='Send' name='poll' /></li>";
echo "</form>";
echo "<li><b>" . $d ."</b>";
echo "<button onclick='JavaScript:changeSheets(1)' style='background-image:url(/misc/FYP/images/def.png); width:40px; height:40px; border:none;'></button>";
echo "<button onclick='JavaScript:changeSheets(2)' style='background-image:url(/misc/FYP/images/def1.png); width:40px; height:40px; border:none;'></button>";
echo "<button onclick='JavaScript:changeSheets(3)' style='background-image:url(/misc/FYP/images/def2.png); width:40px; height:40px; border:none;'></button>";
echo "<button onclick='JavaScript:changeSheets(4)' style='background-image:url(/misc/FYP/images/def3.png); width:40px; height:40px; border:none;'></button></li>";
echo "</ul></div>";
}
$values = array("English","Japanese","Chinese","Hungarian","Arabic","French","Russian","Thai","Korean","German");
$lang_eng1 = array("English","Japanese","Chinese","Hungarian","Arabic");
$lang_eng2 = array("French","Russian","Thai","Korean","German");
$lang_chi = array("English","Japanese","Chinese","Hungarian","Arabic");
$lang_chi2 = array("French","Russian","Thai","Korean","German");
$lang_jap = array("英語","日本語","中国語","ハンガリー語","アラビア語");
$lang_jap2 = array("フランス語","ロシア語","タイ語","韓国語","German");
$lang_rus = array("Английский","Японский","Китайский","Венгерский","Арабский");
$lang_rus2 = array("Французский","Русский","Тайский","Корейский","German");
$lang_kor = array("영어","일어","중국어","헝가리어","아라비아어");
$lang_kor2 = array("프랑스어","러시아어","타이어","한국어","German");
$lang_ger = array("Englisch","Japanisch","Chinesisch","Ungarisch","Arabisch",);
$lang_ger2 = array("Französisch","Russisch","Siamesisch","Koreanisch","German");
$h_eng = "Select Your Language";
$h_chi = "Select Your Language";
$h_jap = "言語の選択";
$h_rus = "Выбрать язык";
$h_kor = "언어 선택";
$h_ger = "Wählen Sie Ihre Sprache vor";
$h2_eng = "Change the Colour Scheme";
$h2_chi = "Change the Colour Scheme";
$h2_jap = "カラースキームの変更";
$h2_rus = "Изменить фон";
$h2_kor = "색채 설계";
$h2_ger = "Ändern Sie den Farbe Entwurf";
?>
在我的网站上,我有一个带有单选框的更改语言功能,如果单击其中一个,则网站的语言将会更改。这看起来像:
上面生成的代码是:
<?php
function selectLang($a,$b,$c,$d,$e,$f,$g){
echo "<div id='menu2' style='width:400px; margin-left:-40px;'> <ul class='triple'>
<li style='background:#333333; color:white; width:400px;'>Demonstration Play Feature</li>";
echo "<form method='post' action=''>";
echo "<li style='width:400px;'>";
while(list(,$values1) = each($c) AND list(,$list) = each($b) AND list(,$list2) = each($e) AND list(,$list3) = each($f) AND list(,$list4) = each($g)) {
echo "<input type='radio' name='languages[]' value='$values1' style='padding:3px;' />" . $list;
echo "<input type='radio' name='languages[]' value='$values1' style='padding:3px;' />" . $list2;
echo "<input type='radio' name='languages[]' value='$values1' style='padding:3px;' />" . $list3;
echo "<input type='radio' name='languages[]' value='$values1' style='padding:3px;' />" . $list4 . "<br />";
}
echo "<input type='submit' value='Send' name='poll' /></li>";
echo "</form>";
echo "</ul></div>";
}
$values = array("English","Japanese","Chinese","Hungarian","Arabic","French","Russian","Thai","Korean","German");
$lang_eng1 = array("English","Japanese","Chinese","Hungarian");
$lang_eng2 = array("French","Russian","Arabic");
$lang_eng3 = array("Thai","Korean","German");
$lang_eng4 = array("Korean","German");
$lang_chi = array("English","Japanese","Chinese","Hungarian","Arabic");
$lang_chi2 = array("French","Russian","Thai","Korean","German");
$lang_jap = array("英語","日本語","中国語","ハンガリー語","アラビア語");
$lang_jap2 = array("フランス語","ロシア語","タイ語","韓国語","German");
$lang_rus = array("Английский","Японский","Китайский","Венгерский","Арабский");
$lang_rus2 = array("Французский","Русский","Тайский","Корейский","German");
$lang_kor = array("영어","일어","중국어","헝가리어","아라비아어");
$lang_kor2 = array("프랑스어","러시아어","타이어","한국어","German");
$lang_ger = array("Englisch","Japanisch","Chinesisch","Ungarisch","Arabisch",);
$lang_ger2 = array("Französisch","Russisch","Siamesisch","Koreanisch","German");
$h_eng = "Select Your Language";
$h_chi = "Select Your Language";
$h_jap = "言語の選択";
$h_rus = "Выбрать язык";
$h_kor = "언어 선택";
$h_ger = "Wählen Sie Ihre Sprache vor";
?>
但是,我不再需要单选/复选框。无论如何,我可以将其更改为下拉框,它仍然可以完全相同地工作吗?
感谢您的任何建议。
**编辑: @高拉夫 我尝试了您的建议,最终代码如下:
<?php
function selectLang($a,$b,$c,$d,$e){
echo "<div id='menu2' style='width:250px; margin-left:-40px;'> <ul class='double'>
<li style='background:#333333; color:white;'>Demonstration Play Feature</li>";
echo "<form method='post' action=''>";
echo "<li>";
while(list(,$values1) = each($c) AND list(,$list) = each($b) AND list(,$list2) = each($e)) {
echo "<input type='radio' name='languages[]' value='$values1' />" . $list;
echo "<input type='radio' name='languages[]' value='$values1' />" . $list2 . "<br />";
}
***echo "<li>";
echo "<select name='languages[]'>";
while(list(,$values1) = each($c) AND list(,$list) = each($b) AND list(,$list2) = each($e) AND list(,$list3) = each($f) AND list(,$list4) = each($g)) {
echo "<option value='$values1'>" . $list ."</option>";
echo "<option value='$values1'>" . $list ."</option>";
echo "<option value='$values1'>" . $list ."</option>";
}
echo "</select>";
echo "</li>";***
echo "<input type='submit' value='Send' name='poll' /></li>";
echo "</form>";
echo "</ul></div>";
}
$values = array("English","Japanese","Chinese","Hungarian","Arabic","French","Russian","Thai","Korean","German");
$lang_eng1 = array("English","Japanese","Chinese","Hungarian","Arabic");
$lang_eng2 = array("French","Russian","Thai","Korean","German");
$lang_chi = array("English","Japanese","Chinese","Hungarian","Arabic");
$lang_chi2 = array("French","Russian","Thai","Korean","German");
$lang_jap = array("英語","日本語","中国語","ハンガリー語","アラビア語");
$lang_jap2 = array("フランス語","ロシア語","タイ語","韓国語","German");
$lang_rus = array("Английский","Японский","Китайский","Венгерский","Арабский");
$lang_rus2 = array("Французский","Русский","Тайский","Корейский","German");
$lang_kor = array("영어","일어","중국어","헝가리어","아라비아어");
$lang_kor2 = array("프랑스어","러시아어","타이어","한국어","German");
$lang_ger = array("Englisch","Japanisch","Chinesisch","Ungarisch","Arabisch",);
$lang_ger2 = array("Französisch","Russisch","Siamesisch","Koreanisch","German");
$h_eng = "Select Your Language";
$h_chi = "Select Your Language";
$h_jap = "言語の選択";
$h_rus = "Выбрать язык";
$h_kor = "언어 선택";
$h_ger = "Wählen Sie Ihre Sprache vor";
$h2_eng = "Change the Colour Scheme";
$h2_chi = "Change the Colour Scheme";
$h2_jap = "カラースキームの変更";
$h2_rus = "Изменить фон";
$h2_kor = "색채 설계";
$h2_ger = "Ändern Sie den Farbe Entwurf";
?>
但它只显示了一个下拉框,下拉框中没有任何值。但这是一个开始,谢谢。关于如何进一步发展这个的任何想法?**
Solution: thanks to the suggestion from @Guarav I was inspired and FINALLY came up with the solution, please tell me what you guys think of my solution and any ways I can improve this further. And yes, thats a challenge. Bet you can't.
<?php
function selectLang($a,$b,$c,$d,$e){
echo "<div id='menu2' style='width:250px; margin-left:-40px;'> <ul class='double'>
<li style='background:#333333; color:white;'>Demonstration Play Feature</li>";
echo "<form method='post' action=''>";
echo "<li><select name='languages[]'>";
while(list(,$values1) = each($c) AND list(,$list) = each($b) AND list(,$list2) = each($e)) {
echo "<option name='languages[]' value='$values1' />" . $list . "</option>";
echo "<option name='languages[]' value='$values1' />" . $list2 . "</option>";
}
echo "</select>";
echo "<input type='submit' value='Send' name='poll' /></li>";
echo "</form>";
echo "<li><b>" . $d ."</b>";
echo "<button onclick='JavaScript:changeSheets(1)' style='background-image:url(/misc/FYP/images/def.png); width:40px; height:40px; border:none;'></button>";
echo "<button onclick='JavaScript:changeSheets(2)' style='background-image:url(/misc/FYP/images/def1.png); width:40px; height:40px; border:none;'></button>";
echo "<button onclick='JavaScript:changeSheets(3)' style='background-image:url(/misc/FYP/images/def2.png); width:40px; height:40px; border:none;'></button>";
echo "<button onclick='JavaScript:changeSheets(4)' style='background-image:url(/misc/FYP/images/def3.png); width:40px; height:40px; border:none;'></button></li>";
echo "</ul></div>";
}
$values = array("English","Japanese","Chinese","Hungarian","Arabic","French","Russian","Thai","Korean","German");
$lang_eng1 = array("English","Japanese","Chinese","Hungarian","Arabic");
$lang_eng2 = array("French","Russian","Thai","Korean","German");
$lang_chi = array("English","Japanese","Chinese","Hungarian","Arabic");
$lang_chi2 = array("French","Russian","Thai","Korean","German");
$lang_jap = array("英語","日本語","中国語","ハンガリー語","アラビア語");
$lang_jap2 = array("フランス語","ロシア語","タイ語","韓国語","German");
$lang_rus = array("Английский","Японский","Китайский","Венгерский","Арабский");
$lang_rus2 = array("Французский","Русский","Тайский","Корейский","German");
$lang_kor = array("영어","일어","중국어","헝가리어","아라비아어");
$lang_kor2 = array("프랑스어","러시아어","타이어","한국어","German");
$lang_ger = array("Englisch","Japanisch","Chinesisch","Ungarisch","Arabisch",);
$lang_ger2 = array("Französisch","Russisch","Siamesisch","Koreanisch","German");
$h_eng = "Select Your Language";
$h_chi = "Select Your Language";
$h_jap = "言語の選択";
$h_rus = "Выбрать язык";
$h_kor = "언어 선택";
$h_ger = "Wählen Sie Ihre Sprache vor";
$h2_eng = "Change the Colour Scheme";
$h2_chi = "Change the Colour Scheme";
$h2_jap = "カラースキームの変更";
$h2_rus = "Изменить фон";
$h2_kor = "색채 설계";
$h2_ger = "Ändern Sie den Farbe Entwurf";
?>
On my website I have a change language feature with radio boxes, if one is clicked then the language of the website will change. This looks like:
The code for what is produced above is:
<?php
function selectLang($a,$b,$c,$d,$e,$f,$g){
echo "<div id='menu2' style='width:400px; margin-left:-40px;'> <ul class='triple'>
<li style='background:#333333; color:white; width:400px;'>Demonstration Play Feature</li>";
echo "<form method='post' action=''>";
echo "<li style='width:400px;'>";
while(list(,$values1) = each($c) AND list(,$list) = each($b) AND list(,$list2) = each($e) AND list(,$list3) = each($f) AND list(,$list4) = each($g)) {
echo "<input type='radio' name='languages[]' value='$values1' style='padding:3px;' />" . $list;
echo "<input type='radio' name='languages[]' value='$values1' style='padding:3px;' />" . $list2;
echo "<input type='radio' name='languages[]' value='$values1' style='padding:3px;' />" . $list3;
echo "<input type='radio' name='languages[]' value='$values1' style='padding:3px;' />" . $list4 . "<br />";
}
echo "<input type='submit' value='Send' name='poll' /></li>";
echo "</form>";
echo "</ul></div>";
}
$values = array("English","Japanese","Chinese","Hungarian","Arabic","French","Russian","Thai","Korean","German");
$lang_eng1 = array("English","Japanese","Chinese","Hungarian");
$lang_eng2 = array("French","Russian","Arabic");
$lang_eng3 = array("Thai","Korean","German");
$lang_eng4 = array("Korean","German");
$lang_chi = array("English","Japanese","Chinese","Hungarian","Arabic");
$lang_chi2 = array("French","Russian","Thai","Korean","German");
$lang_jap = array("英語","日本語","中国語","ハンガリー語","アラビア語");
$lang_jap2 = array("フランス語","ロシア語","タイ語","韓国語","German");
$lang_rus = array("Английский","Японский","Китайский","Венгерский","Арабский");
$lang_rus2 = array("Французский","Русский","Тайский","Корейский","German");
$lang_kor = array("영어","일어","중국어","헝가리어","아라비아어");
$lang_kor2 = array("프랑스어","러시아어","타이어","한국어","German");
$lang_ger = array("Englisch","Japanisch","Chinesisch","Ungarisch","Arabisch",);
$lang_ger2 = array("Französisch","Russisch","Siamesisch","Koreanisch","German");
$h_eng = "Select Your Language";
$h_chi = "Select Your Language";
$h_jap = "言語の選択";
$h_rus = "Выбрать язык";
$h_kor = "언어 선택";
$h_ger = "Wählen Sie Ihre Sprache vor";
?>
However, I dont want the radio/check boxes anymore. Is there anyway i can change this to a drop down box which will still work exactly the same?
thank you for any suggestions.
**Edit:
@Gaurav
I tried you suggestion with the final code which looked like:
<?php
function selectLang($a,$b,$c,$d,$e){
echo "<div id='menu2' style='width:250px; margin-left:-40px;'> <ul class='double'>
<li style='background:#333333; color:white;'>Demonstration Play Feature</li>";
echo "<form method='post' action=''>";
echo "<li>";
while(list(,$values1) = each($c) AND list(,$list) = each($b) AND list(,$list2) = each($e)) {
echo "<input type='radio' name='languages[]' value='$values1' />" . $list;
echo "<input type='radio' name='languages[]' value='$values1' />" . $list2 . "<br />";
}
***echo "<li>";
echo "<select name='languages[]'>";
while(list(,$values1) = each($c) AND list(,$list) = each($b) AND list(,$list2) = each($e) AND list(,$list3) = each($f) AND list(,$list4) = each($g)) {
echo "<option value='$values1'>" . $list ."</option>";
echo "<option value='$values1'>" . $list ."</option>";
echo "<option value='$values1'>" . $list ."</option>";
}
echo "</select>";
echo "</li>";***
echo "<input type='submit' value='Send' name='poll' /></li>";
echo "</form>";
echo "</ul></div>";
}
$values = array("English","Japanese","Chinese","Hungarian","Arabic","French","Russian","Thai","Korean","German");
$lang_eng1 = array("English","Japanese","Chinese","Hungarian","Arabic");
$lang_eng2 = array("French","Russian","Thai","Korean","German");
$lang_chi = array("English","Japanese","Chinese","Hungarian","Arabic");
$lang_chi2 = array("French","Russian","Thai","Korean","German");
$lang_jap = array("英語","日本語","中国語","ハンガリー語","アラビア語");
$lang_jap2 = array("フランス語","ロシア語","タイ語","韓国語","German");
$lang_rus = array("Английский","Японский","Китайский","Венгерский","Арабский");
$lang_rus2 = array("Французский","Русский","Тайский","Корейский","German");
$lang_kor = array("영어","일어","중국어","헝가리어","아라비아어");
$lang_kor2 = array("프랑스어","러시아어","타이어","한국어","German");
$lang_ger = array("Englisch","Japanisch","Chinesisch","Ungarisch","Arabisch",);
$lang_ger2 = array("Französisch","Russisch","Siamesisch","Koreanisch","German");
$h_eng = "Select Your Language";
$h_chi = "Select Your Language";
$h_jap = "言語の選択";
$h_rus = "Выбрать язык";
$h_kor = "언어 선택";
$h_ger = "Wählen Sie Ihre Sprache vor";
$h2_eng = "Change the Colour Scheme";
$h2_chi = "Change the Colour Scheme";
$h2_jap = "カラースキームの変更";
$h2_rus = "Изменить фон";
$h2_kor = "색채 설계";
$h2_ger = "Ändern Sie den Farbe Entwurf";
?>
But it only showed a drop down box, it didnt have any values in the drop box. But its a start thanks. any ideas on how we can develop this further?**
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在函数中使用此代码并让我知道它是否有效。
use this code in function and let me know it works or not.