我有动态表格如图所示。
如何使用jquery或javascript
限制两列中的行具有相同的值提前致谢
答案 0 :(得分:2)
更新:Haim在评论中指出,我可能误解了你的想法。所以我会提出两个选择。
如果您想阻止选择相同的值:
$('table').delegate('select', 'change', function () {
var other = $(this).closest('tr').find('select').not(this);
if (other.val() == $(this).val()) {
// Bad! Now what do you want to do?
// Select nothing?
this.selectedIndex = -1;
// Make the row red?
$(this).closest('tr').css('background-color', 'red');
// Be reallllly annoying?
alert('You have made a bad choice!');
}
});
如果您想保持两列相同:
$('table').delegate('select', 'change', function () {
$(this).closest('tr').find('select').not(this).val($(this).val());
});