Jquery,如何获得下一个元素的值

时间:2015-12-25 22:17:38

标签: jquery html

我希望在输入后得到第二个元素的值。 这是代码:

<div class="col-md-12 nopadding lines">
    <label>
        <input type="checkbox"> {{$e->title}}
        <small class="desc">/  @if($i->ctype==0) Daily@else Weekly @endif</small>
        <small class="price">{{$e->price}} TL</small>
    </label>
</div>

此代码在foreach中迭代。所以我有很多这个块。 我想在ajax的成功功能中达到价格值。 我怎样才能得到这个值?

1 个答案:

答案 0 :(得分:1)

您可以链接两个var DB_contents = {}; // our knowledge and queue store function ensure_DB_has_measure(label) { return new Promise(function(_pass, _fail) { // A more generalised fail function for clarity function fail(err) { // Remove the queue so nothing else waits var original = DB_contents[label]; delete DB_contents[label]; // Inform everything in the queue of the failure if(original instaceof Array) { original.forEach(function(promise) { promise.fail(err); }); } // Follow own failure method _fail.apply(_fail, arguments); } function pass(result) { // Replace the queue with the result so future calls don't query var original = DB_contents[label]; DB_contents[label] = result; // Inform all waiting calls of the result if(original instanceof Array) original.forEach(function(promise) { promise.pass(result); }); // Follow own completion path _pass.apply(_pass, arguments); } // Check to see if it needs to queue if(DB_contents[label] instanceof Array) { DB_contents[label].push({pass:pass, fail:_fail}); // Or if the value is already here it can return } else if(DB_contents[label]) { _pass(DB_contents[label]); // Or it needs to be fetched } else { // Initialise the queue DB_contents[label] = []; // Check for pre-existence FoodMeasureRepository .findOne({"name.en":label}) .then(function(result) { if(result) { pass(result); } else { FoodMeasureRepository .insertOne({name:{en:label, bg:label}}) .then(pass) .catch(fail); } }) .catch(fail) } }); } // The above should go outside the async calls // This can now replace the contents of your second async function body ensure_DB_has_measure(item.label) .then(function(result) { entity.measures.push({ measureId: result._id, value: parseInt(item.eqv) }); callback(); }) .catch(function(err) { callback(err); }) 方法:

.next()

或者你可以使用$('input').next().next(); .nextAll()来获得第二个兄弟姐妹:

.eq()

当然,如果你知道第二个元素的类,你也可以指定它:

$('input').nextAll().eq(1);