English 中文(简体)
Noob j Query “$” function Return question
原标题:Noob jQuery "$" function return question

传真:

<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. I ve试图在id子上“混凝土”。 我尝试:

$( [name=priceperperson +id+ ] );
$( priceperperson +id);

什么是错的?

最佳回答

当你填写<代码>$(>时,请检索j Query物体。

获取价值(string)使用.val(方法。

......

alert( $( input#priceperper......n +id).val() );
问题回答

您可能应将<代码>$列入职能定义。

I m guessing it s causesing the $ changing to be re-fin, in the function -- and not point to the jQuery scode>$ ( function anymore.


I m thinking about this one :

jQuery(document).ready(function($) {

改用:

jQuery(document).ready(function() {

当你穿着 j子时,我认为你必须使用:

页: 1 姓名

并且,从您必须使用的物品中提用价值(美元)或美元(特性);

// Shortcut for doc ready
$(function() 
{ 
 // Loop through values
 var id = $(this).attr( name );

 alert($( input#priceperperson  + id).val());
});

http://api.jquery.com/val/“rel=“nofollow noreferer”>.val()?

this.val(parseInt($( priceperperson +id).val()));

All I ve in alert is "Object"... Value is NaN. I ve tried to "parseInt"

提供<代码>parseInt的基础:

parseInt(variable, 10);

有一种错误,即......必须使用<代码>.val(),而不是

然后, par(Int)作为第二个参数需要rad。 类似:

...
this.value = parseInt($( priceperperson +id).val(), 10) * parseInt($( countpersons +id).val(), 10); 
...

2. 贵 义

your code id = lenght 1 OK if id lenght > 1 ?? possible exception

价格主人1 页: 1

# option # proposal

<input type="text" id="priceperperson_1" name="priceperperson_1" /> // => use "_"
<input type="text" name="personsvalue_1" class="countme" readonly="readonly" />


jQuery(document).ready(function($) {
    $( div.pricerow input.countme ).each(function(){ 
        var id = this.name.split("_")[1]; // => get array value 
        this.value = parseInt($( [name=priceperperson_ +id+ ] ).value()) *parseInt($( [name=countpersons= +id+ ] ).value()); 
    });
});




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!