2013-04-25 43 views
0

顯示結果我有如圖這樣 enter image description here如何在其他文本框與條件的jquery

字段,如果我在結果字段中輸入小於20,則也不/ AB值應automaticaly改變作爲「低」如果輸入超過110,應顯示高其他正常。 所以我只是試圖通過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}&nbsp;-&nbsp;{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使它完成(還記得範圍值是動態的,所以我事先只在20110不能申請條件)...感謝

回答

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/

可能是這可能是有益的。

+0

您可以動態更改所需的data-min和data-max屬性。這裏我只假設了一行。使用類而不是ID來處理多行。 – 2013-04-25 11:48:03

+1

在上面的例子中使用了jQuery 1.9.1。 – 2013-04-25 11:56:19

+0

謝謝先生,+1爲偉大的答案.... – Dinesh 2013-04-25 12:11:00