我有兩個選擇框,我得到了我的選擇的價值,但我想補充我的兩個互相選擇(基本數學運算),可能我可以處理它只有一個功能我使用兩個函數.person-1
和.person-2
如何動態獲取和添加兩個選擇值?
$(document).ready(function(){
$(".person-1").change(function(){
var add_1 = $('option:selected',this).text();
$(".addition-1").text(add_1);
});
$(".person-2").change(function(){
var add_2 = $('option:selected',this).text();
$(".addition-2").text(add_2);
});
});
select{
width:150px;
height:40px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html lang="en">
<head>
<meta charset="UTF-8" />
</head>
<body>
<select class="person-1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<select class="person-2">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<p>Add 1: <span class="addition-1"></span></p>
<p>Add 2: <span class="addition-2"></span></p>
<p>Add 1+2 : <span class="addition"></span> </p>
</body>
</html>
你拍m對它來說,這是我的確切實施。 – localplutonium