0
A
回答
0
得到了一個工作示例爲您運行here。我希望那是你正在尋找的。
HTML
<table>
<tr>
<td>Left</td>
<td><input type="text" id="left-input"/>
</tr>
<tr>
<td>Top</td>
<td><input type="text" id="top-input"/>
</tr>
<tr>
<td>Width</td>
<td><input type="text" id="width-input"/>
</tr>
<tr>
<td>Height</td>
<td><input type="text" id="height-input"/>
</tr>
<tr>
<td>Color</td>
<td><input type="text" id="color-input"/>
</tr>
<tr>
<td>Background Color</td>
<td><input type="text" id="background-color-input"/>
</tr>
<tr>
<td>Text</td>
<td><input type="text" id="text-input"/>
</tr>
<tr>
<td></td>
<td><button type="button" id="save-button">Save</button></td>
</tr>
</table>
<div id="result"></div>
CSS
td {
border: 1px solid black;
}
的JavaScript
const leftInput = document.getElementById('left-input');
const topInput = document.getElementById('top-input');
const widthInput = document.getElementById('width-input');
const heightInput = document.getElementById('height-input');
const colorInput = document.getElementById('color-input');
const textInput = document.getElementById('text-input');
const backgroundColorInput = document.getElementById('background-color-input');
const saveButton = document.getElementById('save-button');
const applyValues =() => {
const left = leftInput.value + "px";
const top = topInput.value + "px";
const width = widthInput.value + "px";
const height = heightInput.value + "px";
const color = colorInput.value;
const backgroundColor = backgroundColorInput.value;
const text = textInput.value;
/*
* You probably want to use `result.style.marginLeft` and `result.style.marginTop`.
*/
result.style.left = left;
result.style.top = top;
result.style.width = width;
result.style.height = height;
result.style.color = color;
result.style.backgroundColor = backgroundColor;
result.innerHTML = text;
console.log(result);
}
saveButton.addEventListener('click', applyValues);
2
你需要做的JavaScript變量,例如
var box_height;
var box_width;
等。然後你需要爲它們分配的div在你的文本框。像:
box_height= document.getElementById('height_input_div').value;
box_width = document.getElementById('width_input_div').value;
等。
,然後你應該能夠改變框的屬性是這樣的:
document.getElementById('myBox').style.height = box_height + "px";
您可以通過將配合這一切的onclick事件它都在一個功能,如:
function getBoxChanges()
{
document.getElementById('myBox').style.height = box_height + "px";
}
相關問題
- 1. 如何使用javascript更改href屬性?
- 2. 如何使用javascript更改css屬性
- 3. 如何使用javascript更改src屬性?
- 4. 如何讓Ldap用戶更改屬性而不是所有用戶屬性
- 5. 如何將此屬性保存到cookie(使用javascript更改div屬性後)
- 6. 使用php更改CSS div的屬性
- 7. 如何用javascript更改CSS屬性?
- 8. 如何使用javascript更改div的CSS
- 9. 使用javascript更改屬性的值
- 10. 用javascript更改html屬性
- 11. 如何在運行時使用watirwebdriver更改div的Style屬性
- 12. 如何使用Javascript更改3rd Div backgroundColor
- 13. 無法使用javascript更改div顯示屬性
- 14. 使用JavaScript更改樣式屬性
- 15. 使用Javascript更改CSS屬性/ jquery
- 16. 使用Javascript更改CSS屬性
- 17. 使用JavaScript更改CSS類屬性
- 18. 使用Javascript更改div
- 19. 使用javascript更改div color
- 20. 使用javascript更改DIV ID
- 21. 如何使用javascript更改元素的屬性值
- 22. 如何使用javascript更改asp.net文本框的文本屬性
- 23. 如何使用javascript更改按鈕的可見/隱藏屬性?
- 24. 如何使用javascript或jquery更改html元素的css屬性
- 25. 如何使用jquery更改css屬性
- 26. 如何使用jQuery更改屬性?
- 27. 使用javascript更改表格行屬性使用javascript
- 28. 如何更改JavaScript中的onclick屬性?
- 29. Javascript - 如何更改組件的屬性?
- 30. 用戶如何更改div的z-index?
您好,歡迎StackOverflow上。請花一些時間閱讀幫助頁面,尤其是名爲[「我可以詢問什麼主題?」(http://stackoverflow.com/help/on-topic)和[「我應該問什麼類型的問題避免問?「](http://stackoverflow.com/help/dont-ask)。更重要的是,請閱讀Stack Overflow [問題清單](http://meta.stackoverflow.com/questions/260648/stack-overflow-question-checklist)。您可能還想了解[最小,完整和可驗證示例](http://stackoverflow.com/help/mcve)。 –
類似於:'div.style.left = document.getElementById(「left」)。value;' – Barmar
當用戶單擊該按鈕時,可以使用類似代碼來更改相應輸入中的每個樣式屬性。 – Barmar