简体   繁体   English

XPages - 更改地方栏按钮的背景颜色

[英]XPages - change background color of place bar button

I would like to change the background color of a place bar button when the button is clicked. 我想在单击按钮时更改位置栏按钮的背景颜色。 How can I do this? 我怎样才能做到这一点? I have considered using Dojo or JavaScript but I don't see how I can get an "id" for the place bar button. 我考虑过使用Dojo或JavaScript,但我不知道如何获得地方栏按钮的“id”。

Tony, 托尼,

You can write simple jQuery to change the color. 你可以编写简单的jQuery来改变颜色。 Instead of using the id, add a class and have jQuery manipulate that. 而不是使用id,添加一个类并让jQuery操纵它。 Marky Roden recently wrote a great article about this. Marky Roden最近写了一篇很棒的文章。

http://xomino.com/2013/08/26/decoupling-your-css-from-your-javascript-a-well-no-duh-moment/ http://xomino.com/2013/08/26/decoupling-your-css-from-your-javascript-a-well-no-duh-moment/

To add a class to a button, go under All Properties, then find attrs, push the plus and it will create an attribute. 要向按钮添加类,请转到“所有属性”下,然后找到“attrs”,按下加号,它将创建一个属性。 Give it a name of "class", and a value of whatever you want to call it. 给它一个“类”的名称,以及你想要它的任何值。 Classes are not unique, so you can have all your buttons have the same behavior by using the same class. 类不是唯一的,因此您可以通过使用相同的类使所有按钮具有相同的行为。

If you gave it a class of "js-foo", then your code would look like: 如果你给它一个“js-foo”类,那么你的代码看起来像:

    $(".js-foo").click(function() {
  $( this ).css( {"background-color" : "red"});
});

(I haven't actually tested this, but this should be close to what you want) (我实际上没有测试过这个,但这应该接近你想要的)

"Another solution like Steve Zavocki in green." “Steve Zavocki的另一个解决方案是绿色。” This Code is not Using jQuery so you dont have to integrate jQuery.js in your application you can do this using native javascript and dojo wich is already integrated in XPages so you dont have much overhead. 此代码不使用jQuery,因此您不必在应用程序中集成jQuery.js,您可以使用本机javascript和dojo,它已经集成在XPage中,因此您没有太多开销。

There are other ways to get an element with javascrip: 还有其他方法可以使用javascrip获取元素:

document.getElementById
dcoument.getElementsBy ClassName, Name, TagName, TagNameNs

with dojo or like Steve used in his code with jQuery: 使用dojo或者像Steve在他的代码中使用jQuery:

<xp:button value="ChangeColor" id="button1">
        <xp:eventHandler event="onclick" submit="false">
            <xp:this.script><![CDATA[var placebar = document.getElementsByClassName("lotusPlaceBar")[0]; //place bar should be unique
placebar.style.backgroundColor = "green";
placebar.style.backgroundImage = "none";
//.. more styling;]]></xp:this.script>
        </xp:eventHandler>
</xp:button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM