2015-10-21 26 views
3

如何添加新的inpu時關閉焦點?我想這樣做,因爲當我在我的iPad上,然後按「添加字段」它會自動彈出鍵盤。這非常煩人,因爲有時我想在輸入數據之前添加一些新的輸入字段。如何添加新的輸入類型時關閉焦點?

\t \t $('.multi-field-wrapper').each(function() { 
 
\t \t \t var $wrapper = $('.multi-fields', this); 
 
\t \t \t $(".add-field", $(this)).click(function(e) { 
 
\t \t \t \t $('.multi-field:first-child', $wrapper).clone(true).appendTo($wrapper).find('input').val('').focus(); 
 
\t \t \t }); 
 
\t \t \t $('.multi-field .remove-field', $wrapper).click(function() { 
 
\t \t \t \t if ($('.multi-field', $wrapper).length > 1) 
 
\t \t \t \t \t $(this).parent('.multi-field').remove(); 
 
\t \t \t }); 
 
\t \t }); 
 
\t \t \t
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<form action="" method="POST" style="height:50px;"> 
 
<input type="submit" name="stocksave" value="Save" class="float" style = "float:right;"> 
 
</br></br> 
 
\t 
 
    <div class="multi-field-wrapper focusoff"> 
 
    
 
\t <div class="multi-fields focusoff"> 
 
\t \t <div class="multi-field focusoff"> 
 
\t \t \t <input type="text" name="stockitem[]" autocomplete="off" class="focusoff"> 
 
\t \t \t <select name='piecesdd[]' style='width:150px; '> 
 
\t \t \t 
 
\t \t \t <option value='0'>PIECES</option> 
 
\t \t \t <?php 
 
\t \t \t \t $count = 1; 
 
\t \t \t \t while ($count<=100) { 
 
\t \t \t \t \t echo "<option value='".$count."'>".$count."</option>"; 
 
\t \t \t \t \t $count++; 
 
\t \t \t \t }; 
 
\t \t \t \t ?> 
 
\t \t \t </select> 
 
\t \t \t <button type="button" class="remove-field">Remove</button> 
 
\t \t \t 
 
\t \t \t <button type="button" class="add-field">Add field</button> 
 
\t \t \t 
 
\t \t </div> 
 
\t \t 
 
\t </div> 
 
     
 
\t </div> 
 
\t 
 
    
 
</form>

+0

你不想把重點新添加的元素然後?! –

回答

2

從下面行.add-field刪除.focus() - click event

$('.multi-field:first-child', $wrapper).clone(true).appendTo($wrapper) 
.find('input').val('').focus() 

因此,這將只是

$('.multi-field:first-child', $wrapper).clone(true).appendTo($wrapper) 
.find('input').val('') 
+1

我希望這不是答案(即使我也是這樣理解),因爲這將是一個愚蠢的問題,不是嗎? :) –

+0

是的,一致同意,但如果OP沒有意識到最後有'.focus',那麼肯定他必須看到這個:) .. @ A.Wolff –

+1

這已經解決了我的問題...抱歉,這對你來說似乎只是一個簡單的問題,但是四年來我一直在關注CSS的焦點。謝謝你BTW @ A.Wolff –

相關問題