【发布时间】:2015-09-25 23:48:58
【问题描述】:
好的,我有一个从数据库返回值的组合框。这一切都是通过 ajax 发生的。用户可以单击一个名为添加新行的按钮,将生成一个新行,该行也将由一个组合框提供支持。 但是,我需要将“onchange”事件附加到 ajax 返回的组合框。
我试过了:-
<script type="text/javascript">
$('.combobox').change(function() {
var va = $('.combobox').val();
alert(va);
});
</script>
但这没有用。我无法收到有关 onchange 事件的任何警报。
我必须尝试什么?
这是我的 ajax :-
try
{
$s = $conn->query("SELECT * FROM testing2");
}
catch(PDOException $e)
{
echo $e->getMessage();
}
$selectBegin = "";
$selectBegin =
'
<select class="combobox">
<option value=""></option>
';
$innerSelectString = "";
$selectMain = "";
while($customers = $s->fetch(PDO::FETCH_OBJ))
{
//fix the select thing here
$si = "<option value='$customers->indexid'>$customers->v1</option>";
$selectMain .= $si;
}
$selectEnd = '</select>';
$selectFinal = $selectBegin . $selectMain . $selectEnd;
return $selectFinal;
有多个组合框,我有这个 jquery 代码来运行组合框:-
function load_content_rows()
{
$(document).ready(function() {
$.ajax({ //create an ajax request to load_page.php
type: "GET",
url: "ajax.php?requestid=1",
dataType: "html", //expect html to be returned
success: function(response){
$("#requestMaker").html(response);
$("#requestMaker").find(".combobox").combobox();
//alert(response);
}
}); //ajax request end
});
} //load_content
load_content_rows();
【问题讨论】:
标签: javascript jquery ajax combobox