为什么这不会改变按钮的高度?

时间:2014-09-03 04:00:13

标签: javascript jquery html

我是JavaScript的新手,我正在尝试创建一个简单的按钮。出于某种原因,按钮的宽度会改变,但高度不会改变。我只是在做些蠢事吗?

document.body.innerHTML = "<span id='pauseButton'</span>";

var button = document.createElement("input");

button.type = "button";
button.value = "Pause";
button.style.height = "50px";
button.style.width = "50px";
button.onclick = function() {
    paused = !paused;
    button.value = paused && "Unpause" || "Pause";
}

document.getElementById("pauseButton").appendChild(button);

2 个答案:

答案 0 :(得分:0)

最好使用div作为按钮而不是按钮作为按钮。您可以更好地控制它。请参阅此示例:Resizing a button

答案 1 :(得分:0)

除了缺少的&#39;&gt;&#39;之外,您所展示的代码没有任何问题。为跨度。为了在创建按钮后更改按钮的高度,请为按钮指定一个id,让我们说按钮1&#39;然后将高度更改为:

document.getElementById("button1").style.height = "200px";

<强> See the DEMO here