简体   繁体   English

动态创建带有悬停文本的“按钮”图像

[英]dynamicaly create “button” image with hover text

I need to create a clickable image with dynamicaly getted text over it. 我需要创建一个可点击的图像,上面有动态获取的文本。 I already have the php that get the information needed for text but i'm having trouble creating the button(i'm really new to this kind of stuff). 我已经有了获取文本所需信息的PHP,但是我在创建按钮时遇到了麻烦(我对这种东西真的很新)。 This is an example of what I'd like to create: 这是我想要创建的示例:

The text "A020310" its a php answer and change all the time(saved in 'stringaPosizione', value of the button). 文本“A020310”是一个php的答案并且一直在变化(保存在'stringaPosizione'中,按钮的值)。 A variable number of this image will be created and will be clicked to start some operation. 将创建此图像的可变数量,并将单击该图像以开始某些操作。

I have a javascript code that create button but they dont have image: 我有一个javascript代码创建按钮,但他们没有图像:

//Create an input type dynamically.
var element = document.createElement("input");

//Assign different attributes to the element.
element.setAttribute("type", "button");
element.setAttribute("class", "mybutt");
element.setAttribute("value", stringaPosizione);
element.setAttribute("name", idMappatura);
element.onclick = function() { runCommand(this) };

css: CSS:

.mybutt {
    background-image: url(/box.png);
    -moz-box-shadow:inset 0px -1px 20px 1px #ffffff;
    -webkit-box-shadow:inset 0px -1px 20px 1px #ffffff;
    box-shadow:inset 0px -1px 20px 1px #ffffff;
    background-color:transparent;
    -moz-border-radius:10px;
    -webkit-border-radius:10px;
    border-radius:10px;
    border:5px solid #dcdcdc;
    display:inline-block;
    color:#777777;
    font-family:arial;
    font-size:20px;
    font-weight:bold;
    padding:10px 40px;
    text-decoration:none;
    text-shadow:1px 3px 4px #ffffff;
}
.mybutt:active {
    position:relative;
    top:1px;
}

Do you have any suggestion? 你有什么建议吗?

Do you are appending the element on any object ? 您是否在任何对象上附加element If not, you're just creating an element on the browser memory but not appending it to the dom tree. 如果没有,您只是在浏览器内存上创建一个元素,但不将其附加到dom树。

Furthermore, you have to set the dimensions of your button to show the entire image. 此外,您必须设置按钮的尺寸以显示整个图像。

Look at this fiddle and tell me if something is missing. 看看这个小提琴 ,告诉我是否缺少某些东西。

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

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