我有多个相互交互的PHP
文件,并且在output.php
文件中有一个名为display_lang_offer()
的函数,该函数在下面显示的lang_offer.php
文件中被调用:
function display_lang_offer(){
//languages offered
?>
<form>
<select name="languages">
<option></option>
<option value"html">HTML</option>
<option value"css">CSS</option>
<option value"js">JavaScript</option>
<option value"csharp">C#</option>
<option value"php">PHP</option>
<option value"java">Java</option>
<option value"phython">Phython</option>
</select>
<br><br>
</form>
<div class="section" id="html">html content here</div>
<div class="section" id="css">CSS content here</div>
<div class="section" id="js">js content here</div>
<div class="section" id="csharp">csharp content here</div>
<div class="section" id="php">php content here</div>
<div class="section" id="java">java content here</div>
<div class="section" id="phython">phython content here</div>
以下是Javascript
代码:
var id;
$("#languages").on("change",function(){
id=$(this).val();
$(".section").hide();
$("#"+id).stop().show();
})
而 CSS
是:
.section{display:none}
当我选择HTML选项时,如何使HTML内容显示出来?然后,如果我选择Java选项,则HTML选项消失,Java选项出现。 编辑 整个函数现在是:
function display_lang_offer(){
//languages offered
?>
<script>
var id;
$("#languages").on("change",function(){
id=$(this).val();
$(".section").hide();
$("#"+id).stop().show();
})
</script>
<style>
.section{display:none;}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<select name="languages"id="languages">
<option></option>
<option value="html">HTML</option>
<option value="css">CSS</option>
<option value="js">JavaScript</option>
<option value="csharp">C#</option>
<option value="php">PHP</option>
<option value="java">Java</option>
<option value="python">Python</option>
</select>
<br><br>
</form>
<div class="section" id="html">html content here</div>
<div class="section" id="css">CSS content here</div>
<div class="section" id="js">js content here</div>
<div class="section" id="csharp">csharp content here</div>
<div class="section" id="php">php content here</div>
<div class="section" id="java">java content here</div>
<div class="section" id="python">python content here</div>
我尝试了两种答案,但似乎都不起作用。
<select id="languages">
- DaniPname
!=id
。$('#foo')
不会找到<select name="foo">
。 - Marc B