<html>
<head>
<title>Index</title>
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<style>
</style>
</head>
<body>
<table id="table"></table>
</body>
<script type="text/javascript">
$(function(){
var b = "<tr>";
for(var i = 0; i < 10; i++){
b += "<td><select></select></td>";
}
b += "</tr>";
$("#table").html(b);
appendOption();
$('#table select:first').on('change',function(){
var val = $(this).val();
for(var i = 0; i < $('select').length; i++){
$('#table select').eq(i).find('option[value='+val+']').attr("selected",true);
}
})
});
function appendOption(){
$('select').append("<option value='111'>111</option>");
$('select').append("<option value='222'>222</option>");
$('select').append("<option value='333'>333</option>");
}
</script>
</html>
这样?
<head>
<title>Index</title>
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<style>
</style>
</head>
<body>
<table id="table"></table>
</body>
<script type="text/javascript">
$(function(){
var b = "<tr>";
for(var i = 0; i < 10; i++){
b += "<td><select></select></td>";
}
b += "</tr>";
$("#table").html(b);
appendOption();
$('#table select:first').on('change',function(){
var val = $(this).val();
for(var i = 0; i < $('select').length; i++){
$('#table select').eq(i).find('option[value='+val+']').attr("selected",true);
}
})
});
function appendOption(){
$('select').append("<option value='111'>111</option>");
$('select').append("<option value='222'>222</option>");
$('select').append("<option value='333'>333</option>");
}
</script>
</html>
这样?
<head>
<title>Index</title>
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<style>
</style>
</head>
<body>
<table id="table"></table>
</body>
<script type="text/javascript">
$(function(){
var b = "<tr>";
for(var i = 0; i < 10; i++){
b += "<td><select></select></td>";
}
b += "</tr>";
$("#table").html(b);
appendOption();
$('#table select').on('change',function(){
var val = $("#table select:first").val();
var index = $('#table select').index(this);
for(var i = 0; i < $('select').length; i++){
if(i != index)
$('#table select').eq(i).find('option[value='+val+']').attr("selected",true);
}
})
});
function appendOption(){
$('select').append("<option value='111'>111</option>");
$('select').append("<option value='222'>222</option>");
$('select').append("<option value='333'>333</option>");
}
</script>
</html> 只跟本行的第一个select一样
<head>
<title>Index</title>
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<style>
</style>
</head>
<body>
<table id="table">
<tr>
<td><select></select></td>
<td><select></select></td>
<td><select></select></td>
<td><select></select></td>
<td><select></select></td>
<td><select></select></td>
<td><select></select></td>
<td><select></select></td>
<td><select></select></td>
<td><select></select></td>
</tr>
</table>
</body>
<script type="text/javascript">
$(function(){
var b = "<tr>";
for(var i = 0; i < 10; i++){
b += "<td><select></select></td>";
}
b += "</tr>";
$("#table").append(b);
appendOption();
$('#table select').on('change',function(){
var val = $(this).parent().parent().find('select:first').val();
var index = $(this).parent().parent().find('select').index(this);
for(var i = 0; i < $('select').length; i++){
if(i != index)
$(this).parent().parent().find('select').eq(i).find('option[value='+val+']').attr("selected",true);
}
})
});
function appendOption(){
$('select').append("<option value='111'>111</option>");
$('select').append("<option value='222'>222</option>");
$('select').append("<option value='333'>333</option>");
}
</script>
</html>
<script type="text/javascript" src="jquery1.9.1.js"></script>
<script type="text/javascript">
$(function(){
var str ="<tr>";
for(var i=0;i<10;i++){
str+="<td><select></select></td>";
}
str+="</tr>";
$("table").append(str);
$("select").append("<option value='111'>111</option>");
$("select").append("<option value='222'>222</option>");
$("select").append("<option value='333'>333</option>");
$("select:first").change(function(){
var v=$(this).children(":selected").val();
$("option[value='"+v+"']").attr("selected","selected");
});
});
</script>
<table></table>这个效果?
<script type="text/javascript">
$(function(){
var str ="<tr>";
for(var i=0;i<10;i++){
str+="<td><select></select></td>";
}
str+="</tr>";
$("table").append(str);
var str1 ="<tr>";
for(var i=0;i<10;i++){
str1+="<td><select></select></td>";
}
str1+="</tr>";
$("table").append(str1);
$("select").append("<option value='111'>111</option>");
$("select").append("<option value='222'>222</option>");
$("select").append("<option value='333'>333</option>");
$("tr").find("select:first").change(function(){
var v=$(this).children(":selected").val();
alert(v);
$(this).parent().parent().find("option[value='"+v+"']").attr("selected","selected");
});
});
</script>
<table></table>