在特定区域显示我的下拉框
display my dropdown box in a specific area
好的,这就是我要做的。基于某个下拉值,我正在创建另一个下拉值。根据我现有的代码,是否可以在特定的区域显示下拉列表。
if (SelectedIndex == 2 || SelectedIndex == 5 || SelectedIndex == 7) {
$("#DomContainer").remove();
var MainContainer = document.createElement("Div");
MainContainer.id = "DomContainer";
$("body").append(MainContainer);
var Options = new Array();
for(var i=1;i<=28;i++){
Options.push(i);
}
AddDropDown(Options);
}
function AddDropDown(Options) {
var selectHTML = "<label>Day:</label> ";
selectHTML += "<select>";
for (i = 0; i < Options.length; i = i + 1) {
selectHTML += "<option value='" + Options[i] + "'>" + Options[i] + "</option>";
}
selectHTML += "</select>";
document.getElementById("DomContainer").innerHTML = selectHTML;
}
For example <div id="new_drop">//Display the drop down here </div>
只需在AddDropDown
中添加第二个参数,即可传递要插入下拉列表的容器的ID:
function AddDropDown(Options, containerId) {
...
document.getElementById(containerId).innerHTML = selectHTML;
然后这样称呼它:
AddDropDown(Options, "new_drop");
(如果我理解正确的话)
无需从DOM中移除和附加元素,只需替换现有的元素内容。。。这是一个简化的版本。
// if "SelectedIndex" is one of the values in the array provided
if ($.inArray(SelectedIndex, [2,5,7])) {
$("#DomContainer").html("<label>Day:</label> "+inject_dropdown(28));
}
// Creates and returns a new drop-down based on the "length" provided
function inject_dropdown(length){
var selectHTML = "<select>";
for( i=1; i<=length; i++ ){
selectHTML += "<option value='" + i + "'>" + i + "</option>"
}
selectHTML += "</select>"
return selectHTML;
}
将$('#DomContainer')
选择器替换为标识新下拉列表显示位置的任何选择器。
相关文章:
- 角度图表;t显示在我的页面中
- 将日期时间作为 JSON 发送将无法在我的视图中正确显示
- 我希望只有在我滚动页面后才能显示我的返回页首图标
- 在我的网站上显示最近提交的文章/图片
- 在主页上时,我的整个导航都会突出显示
- 使用API在我的网站Google-Map上显示搜索地址的纬度和经度
- 当我的条件为true时,显示一条弹出消息
- 为我的rails应用程序显示javascript弹出消息
- 为什么我的视图没有显示在角度ui视图中
- 我的时间倒计时脚本在谷歌浏览器中工作正常,但在其他浏览器中打开时它显示为南楠
- 为什么我的脚本正在运行动画,但没有显示它
- 我如何才能在点击按钮时将我的数字和财富显示在这个脚本上
- 列表没有显示在我的本地主机上,但显示在jsfiddle上
- 为什么我的Alexa技能测试显示正确的lambda输出,但在开发人员控制台中测试时却给出错误消息
- 我的localStorage结果显示了[null,null,“something”]],而不是“”;什么”;
- 希望在单击href链接时显示我的广告
- 我的复选框没有't使用的循环来显示数据
- 我的显示/隐藏功能代码出了什么问题
- 为什么我的显示/隐藏脚本不工作
- 我可以连接到外部服务器和改变我的显示页面