Jquery 打开文本框的焦点清除razor中同一行中的其他文本框
我正在开发mvc应用程序,在我的表格列表中,我在同一行中有两个文本框,我想验证用户只能在一个文本框中输入数据。这两个文本框都是价格,因此用户只能在一个文本框中输入价格。如果在文本框中输入价格,则应在同一行的另一个文本框中写入0。我做了如下操作:Jquery 打开文本框的焦点清除razor中同一行中的其他文本框,jquery,asp.net-mvc-3,asp.net-mvc-4,asp.net-mvc-2,Jquery,Asp.net Mvc 3,Asp.net Mvc 4,Asp.net Mvc 2,我正在开发mvc应用程序,在我的表格列表中,我在同一行中有两个文本框,我想验证用户只能在一个文本框中输入数据。这两个文本框都是价格,因此用户只能在一个文本框中输入价格。如果在文本框中输入价格,则应在同一行的另一个文本框中写入0。我做了如下操作: <td id="tdprice"> <input type="text" id="txtprice" class="inputprice" onfocus="changeValues('@string.Format(" tr{0
<td id="tdprice">
<input type="text" id="txtprice" class="inputprice" onfocus="changeValues('@string.Format(" tr{0} ", @item.Id)','inputmarkup')" value="@string.Format(" {0:0.00} ", item.ManualPrice)" style="width:50px" />
</td>
<td id="tdmarkup">
<input type="text" id="txtmarkup" class="inputmarkup" onfocus="changeValues('@string.Format(" tr{0} ", @item.Id)','inputprice')" value="@string.Format(" {0:0.00} ", item.MarkUp)" style="width:50px" />
</td>
在这个函数中,我得到两个值,第一个是表行和文本框,我想将其设置为0。我该怎么做?而且这个java脚本在第一行被激发了,为什么呢??请立即给予帮助 工作演示
function changeValues(tr, css) {
alert(tr);
alert(css);
var tr1 = "'#" + tr + "'";
var css1 = "'." + css + "'";
$(this).closest(tr1).find(css1).val('');
}
$('table tr td input[type="text"]').focus(function () {
$(this).parent().parent().find('input[type="text"]').not(this).val('');
});