English 中文(简体)
束缚性 h变状态
原标题:styling hover state of a javascript variable

我试图打上我所创造的变量的 h。 我要说的是新鲜的 j,希望你能够帮助我。

此处为:

controlDiv.style.padding =  5px ;

var controlUI = document.createElement( DIV );
controlUI.style.height =  19px ;
controlUI.style.backgroundColor =  #F9F9F9 ;
controlUI.style.background =  linear-gradient(top, #ffffff 0%,#f3f3f3 50%,#ededed 51%,#ffffff 100%) ;
controlUI.style.boxShadow =  2px 2px 2px 1px #999 ;
controlUI.style.borderRadius =  2px ;
controlUI.style.borderStyle =  solid ;
controlUI.style.borderWidth =  1px ;
controlUI.style.borderColor =  #9BADCF ;
controlUI.style.cursor =  pointer ;
controlUI.style.textAlign =  center ;
controlUI.title =  Click Me ;
controlDiv.appendChild(controlUI);

我想要做的是书写文字,为变式控制产生的四舍五入确定不同的风格。 UI, 当该暴徒大声疾呼时。

最佳回答

由于你纯粹与 Java本合作,而不是与中美洲安全共同体合作,你将需要以这种方式,即与事件一道做。 With:

$(controlUI).hover(
    function onMouseEnter() {
        this.style.backgroundColor = "blue";
    },
    function onMouseLeave() {
        this.style.backgroundColor = "#F9F9F9";
    }
);

Without jQuery, you would need to use DOM events, which is a pain because they are not cross-browser compatible with IE less than 9, as discussed extensively in this MDC article. The code ends up looking something like:

var crossBrowserAEL = controlUI.addEventListener ? "addEventListener" : "attachEvent";

controlUI[crossBrowserAEL]("mouseover", function () {
    controlUI.style.backgroundColor = "blue";
});
controlUI[crossBrowserAEL]("mouseout", function () {
    controlUI.style.backgroundColor = "#F9F9F9";
});
问题回答

Try to avoid setting inline styles

定型风格的做法非常坏,因为这种做法难以维持,而你必须从守则中去除某些风格。 如果你使用纯DOM+Javascript的话,我甚至不想触及可能变成实际痛苦的浏览器差异。

A better approach: use CSS classes

Instead of setting particular individual styles on your created element (and writing several lines of code) it s much simpler and better to just apply a CSS class to your element:

controlDiv.className = "some-class";

and then define everything about this class in the CSS file that defines all styles. This will also make it very simple to define related styles (like hover, visited, ::before etc.)





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签