innerText是把对象内的所有内容都替换为文本,所以如果先添加radio,然后再用innerText,radio就会自然消失,被文本取代。
应该用appendChild的方式来添加文本,即:
var label = document.createElement("label")
var radio = document.createElement("input")
radio.type = "radio"
radio.name = "radio"// 名字随意
label.appendChild(radio)
var txt = document.createTextNode("一个radio")
label.appendChild(txt)
document.getElementById("Div").appendChild(label)// Div为父容器id
最后补充说一句:innerHTML和innerText 跟 appendChild 是两种不同的机制,最好不要混用!!!
复制过去就可以运行<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312" />
<title>单选按钮CSS样式处理效果</title>
<style type="text/css">
</style>
<script type="text/javascript">
window.onload = function()
{
labels = document.getElementById('male').getElementsByTagName('label')
radios = document.getElementById('male').getElementsByTagName('input')
for(i=0,j=labels.length i<j i++)
{
labels[i].onclick=function()
{
if(this.className == '') {
for(k=0,l=labels.length k<l k++)
{
labels[k].className=''
radios[k].checked = false
}
this.className='checked'
try{
document.getElementById(this.name).checked = true
} catch (e) {}
}
}
}
}
var male_obj = {'male':'男', 'female':'女','nomale':'人妖'}
function checkform(obj) {
for (i = 0i <obj.sex.lengthi++) {
if (obj.sex[i].checked) {
alert(male_obj[obj.sex[i].value])
var show_msg = document.getElementById("show_msg")
show_msg.value = male_obj[obj.sex[i].value]
}
}
return false
}
</script>
</head>
<body>
<form name="reg" onsubmit="return checkform(this)">
<table border="0">
<tr>
<td><span style="line-height:15px">请选择你的性别:</span></td>
<td width="200" id="male">
<input type="radio" id="sex_male" checked="checked" name="sex" value="male" /><label name="sex_male" class="checked" for="sex_male">男</label>
<input type="radio" id="sex_female" name="sex" value="female" /><label name="sex_female" for="sex_female">女</label>
<input type="radio" id="sex_nomale" name="sex" value="nomale" /><label name="sex_nomale" for="sex_nomale">人妖</label></td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" name="Submit" value="提交" id="Submit" /></td>
</tr>
<tr><td><input type="text" id="show_msg"></td></tr>
</table>
</form>
</body>
</html>
///RadioGroup添加项public void intit()
{
esriGeoAnalysisSlopeEnum m_SlopeType1 = esriGeoAnalysisSlopeEnum.esriGeoAnalysisSlopeDegrees
esriGeoAnalysisSlopeEnum m_SlopeType2 = esriGeoAnalysisSlopeEnum.esriGeoAnalysisSlopePercentrise
DevExpress.XtraEditors.Controls.RadioGroupItem item1 = new DevExpress.XtraEditors.Controls.RadioGroupItem(m_SlopeType1, "坡度")
DevExpress.XtraEditors.Controls.RadioGroupItem item2 = new DevExpress.XtraEditors.Controls.RadioGroupItem(m_SlopeType2, "百分比")
this.radioMethed.Properties.Items.Add(item1)
this.radioMethed.Properties.Items.Add(item2)
}
///listbox项的添加删除
private void AddButton_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog()
ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)//定义打开的默认文件夹位置
ofd.Multiselect = true
ofd.ShowDialog()
string[] fileNames = ofd.FileNames
for (int i = 0i <fileNames.Lengthi++)
{
object obj = fileNames[i] as object
this.listBoxVillage.Items.Add(obj)
}
}
private void DeleteButton_Click(object sender, EventArgs e)
{
this.listBoxVillage.Items.RemoveAt(this.listBoxVillage.SelectedIndex)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)