【发布时间】:2011-06-24 01:54:44
【问题描述】:
我正在使用此代码,效果很好。现在我只需要更改输入的名称,输入 1,输入 2,等等。
<script type="text/javascript">
$(document).ready(function() {
$("#input1 > select.profissao").live('change', function(){
$.ajax({
type: "POST",
data: "data=" + $(this).val(),
url: "drop1.php",
success: function(html) {
$("#input1 > select.estatistica").html(html);
}
});
});
});
</script>
为什么这个版本不起作用?我已经检查了 lint 中的代码,没有检测到错误。 基本上,如果我复制上面的代码并将 input1 更改为 input2,效果很好,但我的目标是减少冗余。
<script type="text/javascript">
$(document).ready(function() {
for (i=1; i<3; i++) {
$("#input"+i+" > select.profissao").live('change', function(){
$.ajax({
type: "POST",
data: "data=" + $(this).val(),
url: "drop1.php",
success: function(html) {
$("#input"+i+" > select.estatistica").html(html);
}
});
});
}
});
</script>
编辑:输出类似于<option value=2>Artes</option><option value=1>Humanidades</option>,但这并未添加到html中
使用循环我的下拉简单停止工作
【问题讨论】:
-
你能把你的 HTML 贴出来吗,我感觉你可以在没有每个输入的事件处理程序的情况下处理这个问题。
标签: javascript loops for-loop