gpt4 book ai didi

jquery 填充选择列表

转载 作者:行者123 更新时间:2023-12-03 22:25:33 25 4
gpt4 key购买 nike

我的 htm 文件中有这个

    <select id="SelItem">

</select>

在我的 javascript 文件中,我有一个 jquery 部分,我有以下内容

     var itemval= '<option value="OT">OT</option>';

$("#SelItem").html(itemval);

以下内容不会用 OT 填充我的下拉菜单吗?它不会填充下拉列表中的任何内容

最佳答案

您可能需要考虑使用append :

//Creates the item
var itemval= '<option value="OT">OT</option>';

//Appends it within your select element
$("#SelItem").append(itemval);​

Example

更新

正如 js1568 所指出的 - 问题很可能是由于执行 JS/jQuery 代码时页面未加载所致。您应该能够通过以下方法解决此问题:

$(document).ready(function()
{
//Creates the item
var itemval= '<option value="OT">OT</option>';

//Appends it within your select element
$("#SelItem").append(itemval);​
});

关于jquery 填充选择列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9998665/

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