使用 jQuery Autosuggest 插件生成复选框

发布于 2024-12-11 11:58:07 字数 945 浏览 5 评论 0原文

我使用 jQuery Autosuggest 插件来选择多个项目(在本例中为城市),并且我想为每个选定的城市生成一个复选框。

到目前为止,我已经修改了脚本,以便将城市名称(每个城市)包含在 Name of city 中,因此更容易得到它。我不知道的是,如何生成这样的复选框:

<input type="checkbox" value="city_id" name="city[]" /> City name

在这种情况下,city_id 将是城市的 id,当前位于隐藏输入中,其中所有 ID 都用逗号分隔(681,215,78 ,),但我也可以将 ID 包装成任何东西,如果这对这种情况有帮助的话(我想会的)。 任何帮助将不胜感激。谢谢

编辑: 我编写了一些代码,添加了第一个城市的复选框,但没有添加其余城市。我还修改了该插件,因此名称如下所示:

City_Name

var timer = setInterval(function() {
            var city = $(".mestoJe").attr("class").replace("mestoJe ", "");
            if(!done){
                var test = $('<input type="checkbox" name="city[]" value="0"> '+city+'</div>');
                $("#checkboxes").append(test);
                done = true;
            }
        }, 2000);

I'm using the jQuery Autosuggest plugin to select multiple items (cities in this case) and I want to generate a checkbox for each selected city.

So far, I've modified the script so, that the name of the city (each city) is wrapped in <span id="city_name">Name of city</span>, so it's easier to get it. What I don't know is, how to generate a checbox like this:

<input type="checkbox" value="city_id" name="city[]" /> City name

city_id in this case would be the id of the city, which is currently in a hidden input, where all the ID's are, separated with a comma (681,215,78,), but I can wrap the ID into anything as well, if that would help the case (i suppose it would).
Any help would be appreciated. Thanks

EDIT:
I've written some code, that adds the checkbox for the first city, but not the rest. I also modified the plugin so the name is wrapped like this: <div class="mestoJe City_Name">City_Name</div>:

var timer = setInterval(function() {
            var city = $(".mestoJe").attr("class").replace("mestoJe ", "");
            if(!done){
                var test = $('<input type="checkbox" name="city[]" value="0"> '+city+'</div>');
                $("#checkboxes").append(test);
                done = true;
            }
        }, 2000);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文