<select name="id[48]" id="attrib-48">
<option value="269" selected="selected">Normal</option>
<option value="270">Rush</option>
</select> 我想直接在显示的时候把<option value="270">Rush</option> 隐藏掉,也就是不展示在网站上。
ps.由于种种原因,这个选项需保留在代码中。
请问如何用js实现?
<option value="269" selected="selected">Normal</option>
<option value="270">Rush</option>
</select> 我想直接在显示的时候把<option value="270">Rush</option> 隐藏掉,也就是不展示在网站上。
ps.由于种种原因,这个选项需保留在代码中。
请问如何用js实现?
<!--<option value="270">Rush </option> -->注释掉,可以么?
在代码中保留? 可不可以考虑在加载后把<option value="270">Rush </option>
这项Remove ?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<style type="text/css"> </style>
</head> <body>
<select name="id[48]" id="attrib-48">
<option value="269" selected="selected">Normal </option>
<option value="270">Rush </option>
</select>
</body>
<script type="text/javascript" defer>
<!--
var sel = document.getElementById("attrib-48");
sel.options.remove(sel.options.length-1);
//-->
</script>
</html>
document.getElementById('attrib-48').Options[1].style.display = 'none';
行倒是行,可以赋给window的一个属性。要的时候再appendChild。
这种情况如何把这些都隐藏掉呢ps.后面的label不能用那个class隐藏
又有个问题诶,这个东西在firefox下面不行啊
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<style type="text/css"> </style>
</head> <body>
<select name="id[48]" id="attrib-48">
<option value="269" selected="selected">Normal </option>
<option value="270">Rush </option>
</select>
</body>
<script type="text/javascript" defer>
<!--
var sel = document.getElementById("attrib-48");
//sel.options.remove(sel.options.length-1);
sel.options[1].setAttribute("txt",sel.options[1].text);
sel.options[1].text="";
alert("值藏起来了:"+sel.options[1].getAttribute("txt"));
//-->
</script>
</html>
先找到select 然后找到你需要隐藏的children()
直接 .hide()
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<style type="text/css"> </style>
</head>
<SCRIPT LANGUAGE="JavaScript">
<!--
/**
* 兼容firefox的 outerHTML 使用以下代码后,firefox可以使用element.outerHTML
**/
if(window.HTMLElement) {
HTMLElement.prototype.__defineSetter__("outerHTML",function(sHTML){
var r=this.ownerDocument.createRange();
r.setStartBefore(this);
var df=r.createContextualFragment(sHTML);
this.parentNode.replaceChild(df,this);
return sHTML;
});
HTMLElement.prototype.__defineGetter__("outerHTML",function(){
var attr;
var attrs=this.attributes;
var str="<"+this.tagName.toLowerCase();
for(var i=0;i<attrs.length;i++){
attr=attrs[i];
if(attr.specified)
str+=" "+attr.name+'="'+attr.value+'"';
}
if(!this.canHaveChildren)
return str+">";
return str+">"+this.innerHTML+"</"+this.tagName.toLowerCase()+">";
});
HTMLElement.prototype.__defineGetter__("canHaveChildren",function(){
switch(this.tagName.toLowerCase()){
case "area":
case "base":
case "basefont":
case "col":
case "frame":
case "hr":
case "img":
case "br":
case "input":
case "isindex":
case "link":
case "meta":
case "param":
case "select":
case "option":
return false;
}
return true;
});
}
//-->
</SCRIPT>
<body>
<select name="id[48]" id="attrib-48">
<option value="269" selected="selected">Normal </option>
<option value="270">Rush </option>
</select>
</body>
<script type="text/javascript" defer>
<!--
var sel = document.getElementById("attrib-48");
sel.options[1].outerHTML="<!-- "+sel.options[1].outerHTML+" -->";
//-->
</script>
</html>
temp.style.display = "none";
JQuery 实现:$('#attrib-48').css("display","none");