ULs没有名字属性,但你可以用标签提及该图。
用以下文字取代第3行:
var sub = cat.getElementsByTagName("UL");
为什么这不会在火ox中发挥作用,试图选择这一类别,然后使子类明显可见。
<script type="text/javascript">
function show_sub(cat) {
var cat = document.getElementById("cat");
var sub = cat.getElementsByName("sub");
sub[0].style.display= inline ;
}
</script>
——
<ul>
<li id="cat" onclick="show_sub(this)">
Top 1
<ul style="display:none" name="sub">
<li>Sub 1</li>
<li>Sub 2</li>
<li>Sub 3</li>
</ul>
</li>
<li>Top 2</li>
<li>Top 3</li>
<li>Top 4</li>
</ul>
EDIT 答复是:
<script type="text/javascript">
function show_sub(cat) {
cat.getElementsByTagName("ul")[0].style.display = (cat.getElementsByTagName("ul")[0].style.display == "none") ? "inline" : "none";
}
</script>
ULs没有名字属性,但你可以用标签提及该图。
用以下文字取代第3行:
var sub = cat.getElementsByTagName("UL");
我建议采取类似行动:
function show_sub(cat) {
if (!cat) {
return false;
}
else if (document.getElementById(cat)) {
var parent = document.getElementById(cat),
sub = parent.getElementsByClassName( sub );
if (sub[0].style.display == inline ){
sub[0].style.display = none ;
}
else {
sub[0].style.display = inline ;
}
}
}
document.getElementById( cat ).onclick = function(){
show_sub(this.id);
};
虽然以上是使用<条码><>>。 而不是<代码> 姓名/代码>属性等于<代码>/>。
至于你最初的“干 t”版本(但我必须补充一点,对问题作特别有用的描述)的原因,我可以建议,在 Ch, Java文 con报告说:
攻击类型 错误:目标号没有方法获得要素 ByName 。
围绕老年和半衰期家庭进行工作的一种做法是使用一种习俗功能来复制getElementsByClassName(
,尽管很粗略:
function eBCN(elem,classN){
if (!elem || !classN){
return false;
}
else {
var children = elem.childNodes;
for (var i=0,len=children.length;i<len;i++){
if (children[i].nodeType == 1
&&
children[i].className == classN){
var sub = children[i];
}
}
return sub;
}
}
function show_sub(cat) {
if (!cat) {
return false;
}
else if (document.getElementById(cat)) {
var parent = document.getElementById(cat),
sub = eBCN(parent, sub );
if (sub.style.display == inline ){
sub.style.display = none ;
}
else {
sub.style.display = inline ;
}
}
}
var D = document,
listElems = D.getElementsByTagName( li );
for (var i=0,len=listElems.length;i<len;i++){
listElems[i].onclick = function(){
show_sub(this.id);
};
}
引证:
function show_sub(cat) {
var parent = cat,
sub = parent.getElementsByClassName( sub );
if (sub[0].style.display == inline ){
sub[0].style.display = none ;
}
else {
sub[0].style.display = inline ;
}
}
document.getElementById( cat ).onclick = function(){
show_sub(this);
};
E6 &,7
if (typeof document.getElementsByClassName!= function ) {
document.getElementsByClassName = function() {
var elms = document.getElementsByTagName( * );
var ei = new Array();
for (i=0;i<elms.length;i++) {
if (elms[i].getAttribute( class )) {
ecl = elms[i].getAttribute( class ).split( );
for (j=0;j<ecl.length;j++) {
if (ecl[j].toLowerCase() == arguments[0].toLowerCase()) {
ei.push(elms[i]);
}
}
} else if (elms[i].className) {
ecl = elms[i].className.split( );
for (j=0;j<ecl.length;j++) {
if (ecl[j].toLowerCase() == arguments[0].toLowerCase()) {
ei.push(elms[i]);
}
}
}
}
return ei;
}
}
I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....
I have a div <div id="masterdiv"> which has several child <div>s. Example: <div id="masterdiv"> <div id="childdiv1" /> <div id="childdiv2" /> <div id="...
I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...
<form><input type="file" name="first" onchange="jsFunction(2);"> <input type="file" name="second" onchange="jsFunction(3);"</form> Possible to pass just numbers to the js ...
So I ve got a menu with a hover/selected state and it loads fine in IE6/IE7. However when I scroll down the page and put the element outside of the viewport and then back in I get a broken image! I ...
I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...
Is it possible to reload a form after file-input change? I have a form where the user can chose an image for upload. I also have a php script which displays that image resized. I only wonder if it ...
I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!