【发布时间】:2011-03-15 11:13:48
【问题描述】:
HTML:
<input type="text" id="priceperperson1" name="priceperperson1" />
<input type="text" name="personsvalue1" class="countme" readonly="readonly" />
JS:
jQuery(document).ready(function($) {
$('div.pricerow input.countme').each(function(){
var id = this.name.substr(this.name.length-1);
alert($('input#priceperperson'+id));
this.value = parseInt($('priceperperson'+id).value) * parseInt($('countpersons'+id).value);
});
});
尽可能缩短。我所有的警报都是“对象”......值是NaN。我试图在 id 上“parseInt”。我试过了:
$('[name=priceperperson'+id+']');
$('priceperperson'+id);
我做错了什么?
【问题讨论】:
-
如果添加以下行会得到什么:alert('input#priceperperson'+id); ?您确定字符串正在按您希望的方式形成吗?
-
您的代码可能包含错误! id = lenght 1 OK 如果 id 长度 > 1 ??可能的例外
标签: javascript jquery html object