html选择控件显示为空 [英] html select control appear empty
本文介绍了html选择控件显示为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
var numOfDep = 0;
var Myvalues = new Array();
var selecID = "";
function FillSelect(selectValue,SelectText)
{
var id = document.getElementById(selecID);
var opt = document.createElement('option');
opt.text = SelectText;
id.appendChild(opt);
}
function AddDependent()
{
numOfDep++;
var mainDiv = document.getElementById('MainDiv');
var newDiv = document.createElement('div');
newDiv.setAttribute('id', "ContainerDiv" + numOfDep);
var newSpan = document.createElement('span');
newSpan.innerHTML = "Insert Dependents No" + numOfDep + ":";
var newTextBox = document.createElement('input');
newTextBox.type = 'text';
newTextBox.id = 'txt_Dep' + numOfDep;
var NewSelect = document.createElement('input');
NewSelect.id = 'select_Rela' + numOfDep;
selecID = NewSelect.id;
newDiv.appendChild(newSpan);
newDiv.appendChild(newTextBox);
newDiv.appendChild(NewSelect);
mainDiv.appendChild(newDiv);
FillSelect("Father");
FillSelect("Mother");
FillSelect("wife");
}
</script>
</head>
<body dir="ltr">
<form id="form1" runat="server">
<div id="MainDiv">
<input id="Button1" type="button" value="Add Dependents" onclick="AddDependent();"/>
</div>
</form>
</body>
</html>
我需要填写选择控件在运行时创建的
I need to fill select control that created in runtime
推荐答案
问题
Problems
- 选择控件创建应该将
选择
作为参数而不是输入
。因此,请更改以下代码...
- The Select Control creation should take
select
as a argument instead ofinput
. So, change following code...
var NewSelect = document.createElement('input');
to。 ..
var NewSelect = document.createElement('select');
FillSelect
函数有两个参数。但它不使用 selectValue
参数。所以,更改以下代码... FillSelect
function takes two parameters. But it does not use selectValue
parameter. So, change following code...FillSelect("Father");
FillSelect("Mother");
FillSelect("wife");
to ...
to...
FillSelect("Father", "Father");
FillSelect("Mother", "Mother");
FillSelect("wife", "wife");
你也可以删除参数 selectValue
来自函数并仅使用 SelectText
参数调用该函数。
You can also delete the parameter selectValue
from function and call the function only with SelectText
parameter.
演示
[问题] html选择控件显示为空 [ ^ ]
这篇关于html选择控件显示为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文