选择使用 jquery 自动完成创建的输入框的值
所以我有这个 jquery:
$(function() {
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
];
$( "#tags" ).autocomplete({
source: availableTags
});
});
var $content = "";
$('#tags').keyup(function() {
$content = $('input').attr('value');
$content2 =$('.ui-widget').parent().html();
$("#placehere").append($content2)
});
$('.ui-widget').parent().css('color', 'red');
和这个 HTML:
<div class="demo">
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags">
</div>
<div id="placehere">Click</div>
</div>
我希望附加到 #placehere
div 的结果只是自动完成表单生成的输入框中的文本。
目前,它只是将所有 .parent()
的 HTML 复制到 .ui-widget
div。
So I have this jquery:
$(function() {
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
];
$( "#tags" ).autocomplete({
source: availableTags
});
});
var $content = "";
$('#tags').keyup(function() {
$content = $('input').attr('value');
$content2 =$('.ui-widget').parent().html();
$("#placehere").append($content2)
});
$('.ui-widget').parent().css('color', 'red');
And this HTML:
<div class="demo">
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags">
</div>
<div id="placehere">Click</div>
</div>
I would like the results which are appended to the #placehere
div to be ONLY the text inside of the input boxes that are generated by the autocomplete form.
Currently, It just copies the HTML of everything .parent()
to the .ui-widget
div.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将无法使用 keyup 事件拉回活动自动完成列表,因为 ui-autocomplete div 尚未创建。您可以通过在 keyup 事件中放置断点来进行验证。您可以通过创建超时或使用带有回调的动画延迟来解决这个问题。
You will not be able to pull back the active autocomplete list using the keyup event because the ui-autocomplete div has not been created yet. You can verify by putting a break point in your keyup event. You can get around that by creating a timeout or using an animated delay with callback.