English 中文(简体)
利用javascript改变风格。 页: 1 FAILS
原标题:using javascript to change style.color of a <label> element FAILS

The following Code work in FF but not in IE9:

     // turn on the  image file upload  field and its label
    document.getElementById( itemImageId ).disabled = false;
    document.getElementById( labelForImageUploadID ).style.color = "black";

这里是带有标签和文档投入的超文本:

    <label for="itemImageId" style="color: silver" id="labelForImageUploadID">Item image
            (select to change the item s current image)</label>
    <input type="file" size="100px" id="itemImageId" disabled="disabled"
                     name="theFileUpload"></input>

** 本文件迟交。 上述标签和上载标签在div内封 我补充说,这样你就可以看到如何处理烟火点。 The handleRowClick() function has the above Javascript Code that tries to consider the text Black:

      <div class="itemlistRowContainer" id="topmostDiv_ID" onclick="handleRowClick(this);"
         onmouseover="handleMouseOver(this);" onmouseout="handleMouseOut(this);"
         ondblclick="handleDblClick(this);">

因此,当这一标签首次出现在网页上时,其颜色是正确的——由于直线颜色,它是一种银。

Then the Javascript code above executes on a mouse click.

Firefox印法将标签文本改为黑体,使文档上载控制成为可能。

然而,在IE9中,贴上标签的文字保持灰色。

IE9不支持e.color = “somecolor”,以动态方式控制的颜色?

I ve looked at a few other posts, and the only quirk I found was that if you have enabling/disabling happening dynamically, to make sure the tag is ENABLED in IE9 before you try to change its color.

That s not a factor here as the code never disables the label tag.

It s not just this one label tag either -- all the label tags on the page fail to turn black but ONLY in IE9 -- in FF everything works.

Is there a gotcha or a trick I m missing?

问题回答

我确定这一点。

最初的问题是:当我把其文字从银改为黑时,我的label标签将不再重写/重写在英、法文本——以下的代码在互联网探索者中倒闭,但欧文如此——下面的代码在FINE中发挥作用。

   // turn on the  image file upload  label
document.getElementById( labelForImageUploadID ).style.color = "black";

SYMPTOMS AND CLUES

Did I know that the above code was, in fact, changing the text of the label to black in IE? Yes. But to see the text color change on the label tags on my page after the above code executed, I had to either:

  • 转播IE浏览器窗户——和BAM:label文本改为黑色

  • or doubleclick in an empty area of the IE browser window -- same effect, the label text would then show the effects of the above code, the text would turn black.

So I knew the color change to black was working in the code, and I learned that the problem "must be that the IE9 browser window is not refreshing the label tag after the color change."

这里是我尝试的两件事,没有效果:

  • 插入zoom:1<>>>>>><>m>,转至 >和括号

  • added a fixed pixel width to the label and to its parent div

这2项尝试是以我读到的

Those things did not help. Besides, I already had display:inline-block for the label s parent div which also (supposedly) forces hasLayout for IE issues.

www.un.org/spanish/ecosoc 内容提要

    // THIS DID NOT WORK IN IE BUT WAS FINE IN Firefox:
       // document.getElementById( labelForImageUploadID ).style.color = "black";

    // THIS WORKS IN IE and IN FIREFOX
    var imageUploadLabel = document.getElementById( labelForImageUploadID );
    imageUploadLabel.style.color = "black";
    imageUploadLabel.style.display = "none";
    imageUploadLabel.style.display = "inline-block"

什么是一部精干的法典。

I m sure there s probably a more elegant way (I thought hasLayout, zoom:1, etc. would work but for me no such luck).

At the time I wrote my solution here, no one had (yet) chimed in with a more elegant way to force IE to redraw my label tags when I change their text color -- maybe after seeing my workaround here someone will provide a more elegant way to force IE to redraw label tags when their text color changes.

iii 我要补充的是,也许我的个人代表处正在造成这一问题——如果你认为是这样的话,就是一个好兆头。 这是我用的网页:

   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

法典规定罚款:

http://jsfiddle.net/AlienWebguy/HKhjs/

我的假设是,你只依靠“addEventlistener(),而只是 Java本。 IE利用它自己称作“J”的护法,该文本使用attachEvent

object.attachEvent(event, callback)




相关问题
CSS working only in Firefox

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....

image changed but appears the same in browser

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. ...

Firefox background image horizontal centering oddity

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 ...

Separator line in ASP.NET

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!