我有一个表格
<form action="" method="POST">
Quantity1: <input type="text" name="quantity1" id="quantity1">
Product1: <select name="product1" id="product1"><option value="1">Product 1</option><option value="2">Product 2</option> ... <option value="15">Product 15</option></select>
Price1: <input type="text" name="price1" id="price1">
Quantity2: <input type="text" name="quantity2" id="quantity2">
Product2: <select name="product1" id="product2"><option value="1">Product 1</option><option value="2">Product 2</option> ... <option value="15">Product 15</option></select>
Price2: <input type="text" name="price2" id="price2">
.
.
.
Quantity15: <input type="text" name="quantity15" id="quantity15">
Product15: <select name="product15" id="product15"><option value="1">Product 1</option><option value="2">Product 2</option> ... <option value="15">Product 15</option></select>
Price15: <input type="text" name="price15" id="price15">
<input type="submit" value="submit">
</form>
我想检查产品是否已经被选中,然后提醒用户这个被选中。我猜应该是这样的
$('select[id^="product"]').change(function() {
//empty array
var selected_values = array();
//check value if it is in array then alert
if ($(this).val() IS IN ARRAY) {
var product = $(this).text();
alert("you have already select this"+product);
} else {
// else save it in array
selected_values[] = $(this).val();
}
}
像这样的http://jsfiddle.net/GKTYE/但提交时会发出警报,我想选择更改。请帮忙!