簡體   English   中英

Javascript onchange函數不適用於PHP

[英]Javascript onchange function does not work with PHP

我寫了一些代碼,使用PHP生成了一個表單。 我想使用javascript(第57行)進行更多更改-通過從下拉菜單(第127行)中選擇內容:

如果選擇值“范圍”,則我想在表格中緊靠該行的位置再生成兩個輸入。

這就是我想要的樣子

// Javascript
$(function() {
    $("#select1").on("change",function() {
        var value = this.value;
        document.getElementById('a').innerHTML = value;
    });
});   

// HTML
<select onchange="select(this.value)" id="select1" name="type$i" size="1">
    <option value="max">Maximum the best</option>
    <option value="min">Minimum the best</option>
    <option value="range">Range</option>
</select>

如果我很了解,這可能是一種方法。 希望能幫助到你!

 $(function() { $("#select1").on("change",function() { var value = $(this).val(); if (value == "range") { $("#select2, #select3").show(); } else { $("#select2 , #select3").hide(); } }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <select id="select1" name="type1" size="1"> <option value="max">Maximum the best</option> <option value="min">Minimum the best</option> <option value="range">Range</option> </select> <select id="select2" name="type2" size="1" style="display:none;"> <option value="max">Maximum the best</option> <option value="min">Minimum the best</option> <option value="range">Range</option> </select> <select id="select3" name="type3" size="1" style="display:none;"> <option value="max">Maximum the best</option> <option value="min">Minimum the best</option> <option value="range">Range</option> </select> 

這樣的簡單示例可能會對您有所幫助。 沒有完整的HTML,我們將無法提供更好的示例。

 function select(value) { if (value == "range") { $('<input>').attr({ type: 'text', id: 'foo1', name: 'bar1' }).appendTo('form'); $('<input>').attr({ type: 'text', id: 'foo2', name: 'bar2' }).appendTo('form'); } } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form> <select onchange="select(this.value)" id="select1" name="type$i" size="1"> <option value="max">Maximum the best</option> <option value="min">Minimum the best</option> <option value="range">Range</option> </select> </form> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM