我正在研究一个项目,我必须对输入字段的现有值进行一些计算.让我们说输入值是400或其他什么.
在下面我有一个选择框YES表示添加425,NO表示添加0或减去-425;
HTML:
<input id="priceTag" name="priceTag" type="text" value="400">
<select id="designChoice" name="designChoice">
<option>Choose--</option>
<option value="yes">yes</option>
<option value="no">no</option>
</select>
Run Code Online (Sandbox Code Playgroud)
jQuery的:
jQuery(document).ready(function($){
var priceTag = $('#priceTag');
$('#designChoice').on('change', function(){
if($(this).val()==='yes'){
/* Here i want to add + 425 to the */
}else{
/* Here I want to add nothing to the input or substract -425 */
}
});
});
Run Code Online (Sandbox Code Playgroud)
我尝试过的:
priceTag.val(+ 425);
/* And more of this type of wrong code ;-P */
Run Code Online (Sandbox Code Playgroud)
我试图查找现有的例子,但我没有找到很多例子,所以提前感谢答案!