jQuery从下拉框的onchange事件中通过ajax加载表单元素
我有下拉列表,需要根据语句动态加载表单元素
input text
case 1加载一些表单元素(inout等..)
案例2清除这些要素……
谢谢
试试这个:
$(function() { $('#type').bind('change', function(ev) { var value = $(this).val(); $.ajax({ ... data: {valueType: value, html: encodeURIComponent($("#addhtml").html())}, ... }); }); });
以下代码通过ajax调用OnChange事件获取数据并填充另一个DropDown
$("#IdOfyourDropDown").change(function () { $.getJSON('<%= ResolveUrl("~/PutYourURL/?Id="1)%>', function (data) { Result = data; //Use this data for further creation of your elements. var items = ""; items += ""; $.each(data, function (i, SingleElement) { items += ""; }); $("#AnyOtherDropDown").html(items); }); });
我使用getJSON来检索数据,你可以使用更多
我们也想尝试一下
$("#type").change(function() { $.post( "yourRequestHandlingPage.php", { param: $(this).val(); }, function(data) { //supposing data holds the html output of dynamically creawted form element $(".myformcontent").append(data); //add the elements at the end of the form elemetn } });