导航:首页 > 编程语言 > jsinnerhtmlselect

jsinnerhtmlselect

发布时间:2022-11-05 15:36:32

javascript 替换select节点的innerHTML 在IE6下出错

var select = document.getElementsByTagName('select')[0];
var o = new Option('1');
if(select){
select.options[0] = o;
select.lenght = 1;
}

IE6下面innerHTML赋值的时候会把所有匹配/^<\w\d['" ]>$/尖括号中间全部为字母,数字,引号和空格等的去掉。
所以:"<option>1</option>";这个进去就变成了:1</option>",显然会BUG的。
还是采用options数组操作吧。

㈡ JAVASCRIPT自定义了一个方法,前台可以用 <script>code.select('', 'DDL1', '', '', '',

C# 不会 。。。你用Ajax获取你那个C#输出的数组 然后在js里循环那个数组 生成Option 再给要显示的div

不管哪有语言,都应该可以输出数组,用json格式

var objdiv=j("#xin_ajax_cwdz_revenue_detail");
objdiv.html("");
objdiv.show();
j.get("./xin/xin_ajax_cwdz_revenue_detail.php",{uid:uid,type:type},function(data){

var table="<table width='100%' border='0' cellspacing='0' cellpadding='0' style='background:#FFFFCC;line-height:16px;'>"+
"<tr>"+
"<td style='height:18px;padding:2px 5px;line-height:18px;color:#666'>序号</td>"+
"<td style='height:18px;padding:2px;line-height:18px;color:#666'>作品ID</td>"+
"<td style='height:18px;padding:2px;line-height:18px;color:#666'>奖项类别</td>"+
"<td style='height:18px;padding:2px;line-height:18px;color:#666'>金额</td>"+
"<td style='height:18px;padding:2px;line-height:18px;color:#666'>奖励时间 </td>"+

"</tr>";
if(data!=''){

//alert(data);

var results=eval('('+data+')');

var counter=1;
if(results!=null){
for(var i=0;i<results.length;i++){

var obj=results[i];
table+="<tr>"+
"<td style='height:18px;padding:2px 5px;line-height:18px'>"+counter+"</td>"+
"<td style='height:18px;padding:2px;line-height:18px'>"+obj.doid+"</td>"+
"<td style='height:18px;padding:2px;line-height:18px'>"+obj.description+"</td>"+
"<td style='height:18px;padding:2px;line-height:18px'>"+obj.revenue+"</td>"+
"<td style='height:18px;padding:2px;line-height:18px'>"+obj.insertDate+"</td>"+

"</tr>";

counter++;
}
}
}
table+="</table>";
//alert(table);
objdiv.html(table);

});

㈢ html的标签,如何获取当前选中的项的内容呢

html中获取标签的数据,可以通过js来获取,如下代码

<script type="text/javascript" src="js/jquery.js"></script>

<script type="text/javascript">

function validate(){

//一 .是通过jDOM
//var attitudeObj = document.getElementById("attitude");
//var attitude = attitudeObj.innerHTML;

//二 .是通过jquery
var att = $("#attitude").text();//可以得到输入域中的内容
var idnum = $("#idnum").val();


var name = $("#name").val();
var t_name = $("#t_name").val() ;
var pro_name = $("#pro_name").val() ;


//alert(att);
if( name == null || name == "" ){

alert("请输入毕业设计名称!");
return false;
}
att = att.replace(/s+/g,"");
if( att == null || att == ""){

alert("请输入选题须知!");
return false;
}
if( t_name == null || t_name == "" ){
alert("请选择教师!");
return false;
}
if( pro_name == null || pro_name == ""){
alert("请选择专业!");
return false;
}

location="teacher/mainfra.jsp";
//location="teacherAction_AddGraationTitle.action?idnum=" + idnum +"&cname=" + cname +"&start=" + start+"&end=" + end;
return true;
}
</script>
</head>

<body">
<div>
<div style="margin-left: 100px;">
<!-- <form action="teacherAction_AddGraationTitle.action" method="post" >-->
<span>自动编号:</span><input type="text" readonly="readonly" name="idnum" id="idnum" style="background: gray;" value="<s:property value="#request.maxIdnum"/>"/><br/>
<br/>
<span>毕业设计名称:</span><input type="text" name="name" id="name"/><br/><br/>
<span>所属教师:</span><select name="t_name" id="t_name">
<option></option>
<s:iterator value="teacherList">
<option value="<s:property value='idnum' />"><s:property value="name" /></option>
</s:iterator>
</select> <br/> <br/>
<span>所属专业:</span><select name="pro_name" id="pro_name">
<option></option>
<s:iterator value="professionList">
<option value="<s:property value='idnum' />"><s:property value="pro_name" /></option>
</s:iterator>
</select>
<br/>
<br/>
<span>选题须知:</span>
<textarea id ="attitude" name="attitude" rows="3" cols="30" style="color: red;">
</textarea>
<br/>

<br/>

<input type="button" value="添加"> <input style="margin-left: 100px" type="reset" value="重置">

<!-- </form> -->
</div>
</div>
</body>


㈣ innerhtml中调用JS自定义函数

<!DOCTYPEHTML>
<html>

<head>
<title>PageTitle</title>
<metahttp-equiv="Content-Type"content="text/html;charset=UTF-8"/>
<script>
onload=function(){
vartrCount=1;
varhtml="<selectstyle="width:100%"name="dis_type_m"+trCount+""id="dis_type_m"+trCount+""class="select"onchange="set_type('dis_type_m"+trCount+"','dis_des_m"+trCount+"','amount"+trCount+"')"><scriptlanguage="text/javascript">headload('dis_type_m"+trCount+"');</script></select>";
document.getElementById("_td3").innerHTML=html;
}
</script>
</head>

<body>
<table>
<tr>
<tdid="_td3"></td>
</tr>
</table>
</body>

</html>

㈤ JS中用innerHTML生成<form:select>的问题

最好在action中转成json格式;

或者像下面一样解析看看。
<c:forEach var="item" items="${user}">
id .push({"name":"${item.name}","id":"${item.id}"});
</c:forEach>

㈥ JS如何获取动态select值(我写的是点击添加)

vargname=document.getElementById("gname").text;

这句不对。应该是

vargname=document.getElementById("gname").value;

不过这样,你拿到的只是选中的id,所以这下很麻专烦,你用原生的属JS还需要

vargnameOptions=document.getElementById("gname").getElementsByTagName('option');

然后遍历一遍,找出符合的id

for(vari=0;i<gnameOptions.length;i+=1){
if(gnameOptions[i].value===gname){
gname=gnameOptions[i].innerHTML;
break;
}
}

㈦ 如何取得写在js内的标签的值我在js里利用innerHTML写了一个select标签。

亲,添加select这个元素的时候也给他添加onchange事件的处理函数,最后在添加到body里面,新添加的select元素就会执行那个onchange事件了了,比如

<scripttype="text/javascript">
varoSelect=document.createElement('select');
varoBody=document.getElementsByTagName('body')[0];
//为新建的select的元素添加事件处理函数
oSelect.onchange=function()
{
//dosomethings
}
//添加select到html的body中
oBody.appendChild(oSelect);
</script>

㈧ 用JavaScript的方法获得TD里面的值

HTML代码:
<table>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
</table>

获取td的值,用innerHTML来获取,方法如下
var td_name=document.getElementsByTagName("td");
for(var i=0;i<td_name.length;i++){
td_name[i].onclick=function(){
console.log(this.innerHTML);
}
}
结果就是点击第一个td,显示1

㈨ JS中用innerHTML动态生成<form:select>的问题

的tb1和tbl怎么弄混了.....还是我弄混的?

你把删除函数改成下面的这样:

function deleteRow(){
var tableObj=document.getElementById("tb1");
var rowNum=tableObj.rows.length-1;
tableObj.deleteRow(rowNum);

}

另外,table表的ID是tb1,不是tbl,这个要注意下,好像真是我弄错的....

㈩ 求一个js日期时间控件,我有一个例子,但功能不能实现

<script language="javascript">
//下面的代码段如果你页面里有,可以去掉
var ie =navigator.appName=="Microsoft Internet Explorer"?true:false;
function $(objID){
return document.getElementById(objID);
}
</script>
</head>
<body>
<script type="text/javascript">
var controlid = null;
var currdate = null;
var startdate = null;
var enddate = null;
var yy = null;
var mm = null;
var hh = null;
var ii = null;
var currday = null;
var addtime = false;
var today = new Date();
var lastcheckedyear = false;
var lastcheckedmonth = false;
function _cancelBubble(event) {
e = event ? event : window.event ;
if(ie) {
e.cancelBubble = true;
} else {
e.stopPropagation();
}
}
function getposition(obj) {
var r = new Array();
r['x'] = obj.offsetLeft;
r['y'] = obj.offsetTop;
while(obj = obj.offsetParent) {
r['x'] += obj.offsetLeft;
r['y'] += obj.offsetTop;
}
return r;
}
function loadcalendar() {
s = '';
s += '<div id="calendar" style="display:none; position:absolute; z-index:9;" onclick="_cancelBubble(event)">';
if (ie)
{
s += '<iframe width="200" height="160" src="about:blank" style="position: absolute;z-index:-1;"></iframe>';
}
s += '<div style="width: 200px;"><table class="tableborder" cellspacing="0" cellpadding="0" width="100%" style="text-align: center">';
///
s += '<tr align="center" class="header"><td class="header"><A href="#" onclick="refreshcalendar(yy-1, mm);return false" title="上一年"><<</A><a href="#" onclick="refreshcalendar(yy, mm-1);return false" title="上一月"><</a></td><td colspan="5" style="text-align: center" class="header"><a href="#" onclick="showdiv(\'year\');_cancelBubble(event);return false" title="点击选择年份" id="year"></a><a id="month" title="点击选择月份" href="#" onclick="showdiv(\'month\');_cancelBubble(event);return false"></a></td><td class="header"><A href="#" onclick="refreshcalendar(yy, mm+1);return false" title="下一月">></A><A href="#" onclick="refreshcalendar(yy+1, mm);return false" title="下一年">>></A></td></tr>';
s += '<tr class="category"><td>日</td><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td>六</td></tr>';
for(var i = 0; i < 6; i++) {
s += '<tr class="altbg2">';
for(var j = 1; j <= 7; j++)
s += "<td id=d" + (i * 7 + j) + " height=\"19\">0</td>";
s += "</tr>";
}
s += '<tr id="hourminute"><td colspan="7" align="center"><input type="text" size="1" value="" id="hour" onKeyUp=\'this.value=this.value > 23 ? 23 : zerofill(this.value);controlid.value=controlid.value.replace(/\\d+(\:\\d+)/ig, this.value+"$1")\'> 点 <input type="text" size="1" value="" id="minute" onKeyUp=\'this.value=this.value > 59 ? 59 : zerofill(this.value);controlid.value=controlid.value.replace(/(\\d+\:)\\d+/ig, "$1"+this.value)\'> 分</td></tr>';
s += '</table></div></div>';///
s += '<div id="calendar_year" onclick="_cancelBubble(event)"><div class="col">';
for(var k = 1930; k <= 2069; k++) {
s += k != 1930 && k % 10 == 0 ? '</div><div class="col">' : '';
s += '<a href="#" onclick="refreshcalendar(' + k + ', mm);$(\'calendar_year\').style.display=\'none\';return false"><span' + (today.getFullYear() == k ? ' class="today"' : '') + ' id="calendar_year_' + k + '">' + k + '</span></a><br />';
}
s += '</div></div>';
s += '<div id="calendar_month" onclick="_cancelBubble(event)">';
for(var k = 1; k <= 12; k++) {
s += '<a href="#" onclick="refreshcalendar(yy, ' + (k - 1) + ');$(\'calendar_month\').style.display=\'none\';return false"><span' + (today.getMonth()+1 == k ? ' class="today"' : '') + ' id="calendar_month_' + k + '">' + k + ( k < 10 ? ' ' : '') + ' 月</span></a><br />';
}
s += '</div>';
var nElement = document.createElement("div");
nElement.innerHTML=s;
document.getElementsByTagName("body")[0].appendChild(nElement);
//document.write(s);
document.onclick = function(event) {
$('calendar').style.display = 'none';
$('calendar_year').style.display = 'none';
$('calendar_month').style.display = 'none';
}
$('calendar').onclick = function(event) {
_cancelBubble(event);
$('calendar_year').style.display = 'none';
$('calendar_month').style.display = 'none';
}
}
function parsedate(s) {
/(\d+)\-(\d+)\-(\d+)\s*(\d*):?(\d*)/.exec(s);
var m1 = (RegExp.$1 && RegExp.$1 > 1899 && RegExp.$1 < 2101) ? parseFloat(RegExp.$1) : today.getFullYear();
var m2 = (RegExp.$2 && (RegExp.$2 > 0 && RegExp.$2 < 13)) ? parseFloat(RegExp.$2) : today.getMonth() + 1;
var m3 = (RegExp.$3 && (RegExp.$3 > 0 && RegExp.$3 < 32)) ? parseFloat(RegExp.$3) : today.getDate();
var m4 = (RegExp.$4 && (RegExp.$4 > -1 && RegExp.$4 < 24)) ? parseFloat(RegExp.$4) : 0;
var m5 = (RegExp.$5 && (RegExp.$5 > -1 && RegExp.$5 < 60)) ? parseFloat(RegExp.$5) : 0;
/(\d+)\-(\d+)\-(\d+)\s*(\d*):?(\d*)/.exec("0000-00-00 00\:00");
return new Date(m1, m2 - 1, m3, m4, m5);
}
function settime(d) {
$('calendar').style.display = 'none';
controlid.value = yy + "-" + zerofill(mm + 1) + "-" + zerofill(d) + (addtime ? ' ' + zerofill($('hour').value) + ':' + zerofill($('minute').value) : '');
}
function showcalendar(event, controlid1, addtime1, startdate1, enddate1) {
controlid = controlid1;
addtime = addtime1;
startdate = startdate1 ? parsedate(startdate1) : false;
enddate = enddate1 ? parsedate(enddate1) : false;
currday = controlid.value ? parsedate(controlid.value) : today;
hh = currday.getHours();
ii = currday.getMinutes();
var p = getposition(controlid);
$('calendar').style.display = 'block';
$('calendar').style.left = p['x']+'px';
$('calendar').style.top = (p['y'] + 20)+'px';
_cancelBubble(event);
refreshcalendar(currday.getFullYear(), currday.getMonth());
if(lastcheckedyear != false) {
$('calendar_year_' + lastcheckedyear).className = 'default';
$('calendar_year_' + today.getFullYear()).className = 'today';
}
if(lastcheckedmonth != false) {
$('calendar_month_' + lastcheckedmonth).className = 'default';
$('calendar_month_' + (today.getMonth() + 1)).className = 'today';
}
$('calendar_year_' + currday.getFullYear()).className = 'checked';
$('calendar_month_' + (currday.getMonth() + 1)).className = 'checked';
$('hourminute').style.display = addtime ? '' : 'none';
lastcheckedyear = currday.getFullYear();
lastcheckedmonth = currday.getMonth() + 1;
}
function refreshcalendar(y, m) {
var x = new Date(y, m, 1);
var mv = x.getDay();
var d = x.getDate();
var dd = null;
yy = x.getFullYear();
mm = x.getMonth();
$("year").innerHTML = yy;
$("month").innerHTML = mm + 1 > 9 ? (mm + 1) : '0' + (mm + 1);
for(var i = 1; i <= mv; i++) {
dd = $("d" + i);
dd.innerHTML = " ";
dd.className = "";
}
while(x.getMonth() == mm) {
dd = $("d" + (d + mv));
dd.innerHTML = '<a href="###" onclick="settime(' + d + ');return false">' + d + '</a>';

if(x.getTime() < today.getTime() || (enddate && x.getTime() > enddate.getTime()) || (startdate && x.getTime() < startdate.getTime())) {
dd.className = 'expire';
} else {
dd.className = 'default';
}
if(x.getFullYear() == today.getFullYear() && x.getMonth() == today.getMonth() && x.getDate() == today.getDate()) {
dd.className = 'today';
dd.firstChild.title = '今天';
}
if(x.getFullYear() == currday.getFullYear() && x.getMonth() == currday.getMonth() && x.getDate() == currday.getDate()) {
dd.className = 'checked';
}
x.setDate(++d);
}
while(d + mv <= 42) {
dd = $("d" + (d + mv));
dd.innerHTML = " ";
d++;
}
if(addtime) {
$('hour').value = zerofill(hh);
$('minute').value = zerofill(ii);
}
}
function showdiv(id) {
var p = getposition($(id));
$('calendar_' + id).style.left = p['x']+'px';
$('calendar_' + id).style.top = (p['y'] + 16)+'px';
$('calendar_' + id).style.display = 'block';
}
function zerofill(s) {
var s = parseFloat(s.toString().replace(/(^[\s0]+)|(\s+$)/g, ''));
s = isNaN(s) ? 0 : s;
return (s < 10 ? '0' : '') + s.toString();
}
loadcalendar();
</script>
</head>
<style>
table tr .td_bg { text-align:left; padding-left:10px;}
#att_info tr td { padding:3px; padding-left:10px;}
.header {font: 12px Arial, Tahoma !important;font-weight: bold !important;font: 11px Arial, Tahoma;font-weight: bold;color: #154BA0;background:#C2DEED;height: 25px;padding-left: 10px;
}
.header td {padding-left: 10px;}
.header a {color: #154BA0;}
.header input {background:none;vertical-align: middle;height: 16px;}
.category {font: 12px Arial, Tahoma !important;font: 11px Arial, Tahoma;color: #92A05A;height:20px;background-color: #FFFFD9;}
.category td {border-bottom: 1px solid #DEDEB8;}
.expire, .expire a:link, .expire a:visited {color: #999999;}
.default, .default a:link, .default a:visited {color: #000000;}
.checked, .checked a:link, .checked a:visited {color: #FF0000;}
.today, .today a:link, .today a:visited {color: #00BB00;}
#calendar_year {display: none;line-height: 130%;background: #FFFFFF;position: absolute;z-index: 10;}
#calendar_year .col {float: left;background: #FFFFFF;margin-left: 1px;border: 1px solid #86B9D6;padding: 4px;}
#calendar_month {display: none;background: #FFFFFF;line-height: 130%;border: 1px solid #86B9D6;padding: 4px;position: absolute;z-index: 11;}
.tableborder {background: white;border: 1px solid #86B9D6;}
#year,#month{padding-right:10px;}
</style>
<tr>
<td class="td_bg" width="10%">生日:</td>
<td class="td_bg" height="26" colspan="3"><input type="text" name="shengri" value="" size="14" onClick="showcalendar(event,this);" onFocus="showcalendar(event,this);"/></td>
</tr>

阅读全文

与jsinnerhtmlselect相关的资料

热点内容
电脑下载评书什么网站好用 浏览:359
跨平台传文件 浏览:609
同花顺如何调用昨天的数据函数 浏览:617
extjsgrid图片大小 浏览:931
没有数据的大数据报告 浏览:405
学科学习网站有哪些 浏览:931
win10鼠标右键不能粘贴文件 浏览:607
中阳小姐微信 浏览:85
安卓误删系统文件 浏览:987
win10怎么删除隐藏流氓文件 浏览:84
excel怎么以文件格式发送 浏览:747
cad的工作空间文件格式 浏览:818
派派新版本下载2017 浏览:831
iphonesafari下载文件 浏览:955
打开的网站有广告怎么办 浏览:361
外资大数据 浏览:600
慈溪小孩子学编程哪里好 浏览:105
南邮大数据盐城 浏览:239
摄像头二维码java 浏览:258
屏幕录制教程 浏览:576