0
我的代碼如下。我從一個網站得到它。但我認爲缺少一些東西。請幫我完成我的任務。在此先感謝如何實現動態創建文本框的自動提示
// HTML
<div class="input_fields_wrap">
<button class="add_field_button">Add More Fields</button>
<div><input type="text" name="mytext[]"></div>
</div>
// JS
var availableAttributes = [
"account_address",
"account_address_city",
"account_address_country",
"account_address_state",.
"account_address_street1",
"account_address_street2",
"account_address_zip",
"account_email",
"account_login",
"account_name",
"account_number",
"account_telephone"
];
$(document).ready(function() {
var max_fields = 10; //maximum input boxes allowed
var wrapper = $(".input_fields_wrap"); //Fields wrapper
var add_button = $(".add_field_button"); //Add button ID
var x = 1; //initlal text box count
$(add_button).click(function(e){ //on add input button click
e.preventDefault();
if(x < max_fields){ //max input box allowed
x++; //text box increment
$(wrapper).append('<div><input id="' + x + '" type="text" name="mytext"/><a href="#" class="remove_field">Remove</a></div>');
//add input box
$("input[id="+ x +"]").autocomplete({
source: availableAttributes
});
}
});
});
請提供更多的細節後,工作演示codepen。這段代碼有什麼問題嗎?爲什麼它不適合你? –
請編輯,以使代碼塊的最後一位代碼部分... –
@RoryMcCrossan我認爲一些鏈接丟失。你能建議適當的鏈接嗎? –