我有这样的领域
如图所示,如果我在结果字段中输入小于20,那么如果输入超过110,则nor / ab值应自动更改为“低”,否则应显示为高正常。 所以我只是尝试了jquery并没有成功......让我看看我的表格。
<div style=" width:900px; height:auto; float:left; text-align:center;">
<div style=" height:auto; width:140px; float:left">{title}</div>
<div style=" height:30px; width:140px; float:left"><input type="text" height="30px" width="140" name="rep_result_{txt}" /></div>
<div style=" height:30px; width:140px; float:left">{unit}</div>
<div style=" height:30px; width:140px; float:left">{first_val} - {last_val}</div>
<div style=" height:30px; width:140px; float:left"><input type="text" height="30px" width="140" name="remark_{txt}" >
你可以看到我在两个部分first_val(表示20)和last_val(表示110)中输入了范围值,所以我如何使用jquery使其完整(记住范围值是动态的,所以我不能仅应用条件20,110)...提前谢谢
答案 0 :(得分:2)
HTML
<input type='text' id='result' />
<input type='text' id='nor' data-min='20' data-max='110' />
的JavaScript
$('#result').change(function() {
var result = $(this).val(),
nor = $('#nor'),
min = nor.data('min'),
max = nor.data('max');
if(result < min) {
nor.val('Low');
} else if (result < max) {
nor.val('Normal');
} else {
nor.val('High');
}
});
JSFiddle:http://jsfiddle.net/BbPC7/
这可能会有所帮助。