我正在处理一个项目,我必须对输入字段的现有值进行一些计算。假设输入值是400或其他。使用.val()计算输入jQuery
下方我有一个选择框YES手段添加,NO手段添加或-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>
的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 */
}
});
});
我已经试过:
priceTag.val(+ 425);
/* And more of this type of wrong code ;-P */
我试图查找现有的例子,但我没有找到很多例子都非常感谢您的回答!
你tottaly对的,我西港岛线编辑自己的帖子,谢谢! – Paul
在“否”的情况下,您是否减去425,并且在哪个值中保留该值?这是一个重要的观点,否则你的问题不能得到妥善的回答。 – Christoph
他的意思是,如果点击'yes',如果已经添加了'no',则应该减去425。 –