尊敬的专家们:
我正在关注 先生.Steve Sanderson 示例,用于使用 ASP.NET MVC 2 样式的可变长度列表。
在我的场景中,我有一个文本框,用户通过条形码扫描仪进行扫描,扫描的条形码的值将分布在变量列表输入字段中。
我正在使用 JQuery 设置这些生成字段的值,
动态生成的 DIV 的示例是
<div class="editorRow">
<input type="hidden" name="gifts.index" autocomplete="off" value="a041d40e-d016-4543-b3f1-bf72239e1377" />
Area Code <input id="gifts_a041d40e-d016-4543-b3f1-bf72239e1377__AreaCode" name="gifts[a041d40e-d016-4543-b3f1-bf72239e1377].AreaCode" type="text" value="0" />
Account No: <input id="gifts_a041d40e-d016-4543-b3f1-bf72239e1377__ConsCode" name="gifts[a041d40e-d016-4543-b3f1-bf72239e1377].ConsCode" type="text" value="0" />
Amount: <input id="gifts_a041d40e-d016-4543-b3f1-bf72239e1377__CAmount" name="gifts[a041d40e-d016-4543-b3f1-bf72239e1377].CAmount" type="text" value="0" />
Coll No: <input Value="1" id="gifts_a041d40e-d016-4543-b3f1-bf72239e1377__CollNo" name="gifts[a041d40e-d016-4543-b3f1-bf72239e1377].CollNo" type="text" value="1" />
<a href="#" class="deleteRow">delete</a>
<span class="field-validation-valid" id="gifts_a041d40e-d016-4543-b3f1-bf72239e1377__AreaCode_validationMessage"></span>
<span class="field-validation-valid" id="gifts_a041d40e-d016-4543-b3f1-bf72239e1377__ConsCode_validationMessage"></span>
<span class="field-validation-valid" id="gifts_a041d40e-d016-4543-b3f1-bf72239e1377__CAmount_validationMessage"></span>
如果您看到有一个隐藏字段具有索引和值=“a041d40e-d016-4543-b3f1-bf72239e1377”,这在其他具有其名称的成员中很常见。当我再添加一个 DIV 时,隐藏的输入值再次发生变化,并且该 div 的所有成员都具有相同的公共值。
我不知道如何处理它,到目前为止,我已经成功地将扫描条形码的值分发到动态 DIV 之外的输入框,例如:
$("#ScanBCode").keyup(function (e) {
barCode = $("#ScanBCode").val();
if (barCode.length == 21) {
var count = 1;
Checking(count);
}
function Checking(count) {
var code = barCode.substr(2, 3);
var ACode = barCode.substr(5, 3);
var Ccode = barCode.substr(8, 5);
var Amount = barCode.substr(13, 8) / 1000;
$("#TabACode").val(ACode);
$("#TabCCode").val(Ccode);
$("#TabAmount").val(Amount);
$("#TabCollNo").val(code);
$("#ScanBCode").val("");
}
});
任何想法
Dear Experts,
I am following Mr.Steve Sanderson Example for working with variable length list, ASP.NET MVC 2-style.
In my Scenario I have one text box in which a user scan through a barcode scanner and the value of scanned barcode will distributed in variable list input fields.
I am using JQuery to set Values of those generated fields,
Example of dynamically Generated DIV is
<div class="editorRow">
<input type="hidden" name="gifts.index" autocomplete="off" value="a041d40e-d016-4543-b3f1-bf72239e1377" />
Area Code <input id="gifts_a041d40e-d016-4543-b3f1-bf72239e1377__AreaCode" name="gifts[a041d40e-d016-4543-b3f1-bf72239e1377].AreaCode" type="text" value="0" />
Account No: <input id="gifts_a041d40e-d016-4543-b3f1-bf72239e1377__ConsCode" name="gifts[a041d40e-d016-4543-b3f1-bf72239e1377].ConsCode" type="text" value="0" />
Amount: <input id="gifts_a041d40e-d016-4543-b3f1-bf72239e1377__CAmount" name="gifts[a041d40e-d016-4543-b3f1-bf72239e1377].CAmount" type="text" value="0" />
Coll No: <input Value="1" id="gifts_a041d40e-d016-4543-b3f1-bf72239e1377__CollNo" name="gifts[a041d40e-d016-4543-b3f1-bf72239e1377].CollNo" type="text" value="1" />
<a href="#" class="deleteRow">delete</a>
<span class="field-validation-valid" id="gifts_a041d40e-d016-4543-b3f1-bf72239e1377__AreaCode_validationMessage"></span>
<span class="field-validation-valid" id="gifts_a041d40e-d016-4543-b3f1-bf72239e1377__ConsCode_validationMessage"></span>
<span class="field-validation-valid" id="gifts_a041d40e-d016-4543-b3f1-bf72239e1377__CAmount_validationMessage"></span>
if you see there is one hidden field having index and value="a041d40e-d016-4543-b3f1-bf72239e1377" which is common in other members with their names. When I add one more DIV the hidden input value again change and all members of that div having the same common value.
I am stuck how to deal with it, so far I have successfully distributed the value of scan barcode to the input boxes which are out side of that dynamic DIVs like:
$("#ScanBCode").keyup(function (e) {
barCode = $("#ScanBCode").val();
if (barCode.length == 21) {
var count = 1;
Checking(count);
}
function Checking(count) {
var code = barCode.substr(2, 3);
var ACode = barCode.substr(5, 3);
var Ccode = barCode.substr(8, 5);
var Amount = barCode.substr(13, 8) / 1000;
$("#TabACode").val(ACode);
$("#TabCCode").val(Ccode);
$("#TabAmount").val(Amount);
$("#TabCollNo").val(code);
$("#ScanBCode").val("");
}
});
Any Idea
发布评论
评论(2)
不确定我是否正确,但似乎您正在寻找一种循环 jquery 集合的方法,这可以使用 jQuery.each。
因此,我建议不要在输入字段上留意某些生成的 ID,而是循环遍历所有生成的“字段”(由其类
editorRow
标识)。请注意,您不必为每个输入字段设置单独的 id,而是必须为它们设置一些类,例如:现在您可以在
keyup
处理程序中应用以下 javascript:只需发布如果这里有不清楚的地方,请回来。
not sure wheter i got this one right, but it seems you're looking for a way to loop over a jquery collection, which can be done using jQuery.each.
so instead of watching out for some generated IDs on your input field, i'd recommend looping over all of your generated 'fields', itentified by their class
editorRow
. just note that instead of having a separate id for each input field, you'd have to set some class on them, for example:now you can apply the following javascript inside of your
keyup
handler:just post back in case something isn't clear here.
你太棒了,它工作得很好,我的工作代码是,
You are great its working fine my working code is,