2013-03-08 66 views
0

你好,我有很多带有“价格”类的文本框, 我想要做的就是用与第一个文本框相同的值来提供所有其他文本框。这是我的代码,但它不工作。根据第一个文本框的值jquery提供所有文本框

$firstprice=$("."+$sectionwrapper).find(".price").first().val(); 
$("."+$sectionwrapper).find(".price:eq(0)").nextAll(".price").val($firstprice); 

我在哪里出错?任何帮助将不胜感激。

编辑

这是我的HTML代码

<div class="section-1"> 
    <div id="bookin-ad-wrapper"> 
     <div class="booking-wrapper booking-wrapper-5"> 
      <ul> 
      <li><label class="w50">Pris kr</label><input type="text" value="" class="price numeric required" name="txtSection[1][5][price]" style=""></li> 
      </ul> 
     </div> 
     <div class="booking-wrapper booking-wrapper-6"> 
      <ul> 
      <li><label class="w50">Pris kr</label><input type="text" value="" class="price numeric required" name="txtSection[1][6][price]"></li> 
      </ul> 
     </div> 
     <div class="booking-wrapper booking-wrapper-0"> 
      <ul> 
      <li><label class="w50">Pris kr</label><input type="text" value="" class="price numeric required" name="txtSection[1][0][price]"></li> 
      </ul> 
     </div> 
    </div> 
</div> 

$ sectionwrapper表示类 “部分-1”

感谢

+0

你能告诉我们HTML或作出小提琴? – Adil 2013-03-08 05:15:38

+0

是的,只有在看到HTML后我们才能说。 – 2013-03-08 05:15:50

+0

@Adil,我已更新问题 – WatsMyName 2013-03-08 05:21:53

回答

1

尝试这样JSFiddle Demo

$('input.price').val($('.price').eq(0).val()) 

或这样

$('input.price:gt(0)').val($('input.price').eq(0).val()); 

或使用第一算子。

$('input.price').val($('input.price').first().val()); 

你可以把它挂在你想要的任何事件中。可能会点击,更改。

+0

这工作多亏 – WatsMyName 2013-03-08 05:29:31

+0

@LoVeSmItH很高兴它的工作:) upvote it:D – 2013-03-08 05:30:06

0

试试这个:

$(document).ready(function(){ 
    $('input.price:gt(0)').val($('input.price:eq(0)').val()); 
}); 

JSFIDDLE

0

这里是fiddle

$(".price").on("change",function() 
       {$(".price").val($(".price").first().val()) 
       }); 
0
Try this: 

    $(document).ready(function(){ 
    $(".section-1").find(".price").first().blur(function() { 
       var firstprice=$(".section-1").find(".price").first().val(); 
       //alert("val"+ firstprice); 
       if(firstprice) 
       $(".section-1").find(".price").val(firstprice); 
     }); 
    }); 
相关问题