2013-03-08 65 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); 
     }); 
    }); 
相關問題