gpt4 book ai didi

javascript - jQuery : How to operate a plugin on two input boxes

转载 作者:行者123 更新时间:2023-12-02 15:25:24 25 4
gpt4 key购买 nike

我正在编写一个类似于自动完成或虚拟键盘的插件,其中包含选定的输入值以及排序和搜索。如果我在一页中使用它一次,这个插件工作得很好,但是当我将这个插件应用到多个页面时,它会显示框和事件都应用于最后一个写入的对象。示例代码和 fiddle 如下: http://jsfiddle.net/mantrig/ugmwa5b5/

我的插件代码:

$(document).ready(function(){
var testData = ["BSL","DSK","NPNR","SAV","ET","NDLS","JPR","MAS","BCT","NZM","BR","SUJH"];
$(".stations").myAutoSuggest({
data:testData,
dataref:"stationsList",
title:"Station List",
sort:"desc"
});
var trainData = ["12345","32151","64231","56421","78542","13452"];
$(".trains").myAutoSuggest({
data:trainData,
title:"Train List",
dataref:"trainsList",
sort:"desc"
});
});

我对编写任何插件都很陌生,因此代码可能非常脏。一点帮助将不胜感激!

最佳答案

您错过了'。将 $(body).append(html); 更改为 $('body').append(html);

Jsfiddle

关于javascript - jQuery : How to operate a plugin on two input boxes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33729776/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com