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更改css属性
- 2. 如何使用javascript更改src属性?
- 3. 如何让Ldap用户更改属性而不是所有用户属性
- 4. 如何将此属性保存到cookie(使用javascript更改div属性后)
- 5. 使用php更改CSS div的属性
- 6. 如何用javascript更改CSS属性?
- 7. 使用javascript更改属性的值
- 8. 如何使用Javascript更改3rd Div backgroundColor
- 9. 使用Javascript更改CSS属性/ jquery
- 10. 使用JavaScript更改CSS类属性
- 11. 使用Javascript更改CSS属性
- 12. 使用JavaScript更改样式属性
- 13. 如何使用javascript或jquery更改html元素的css属性
- 14. 如何使用javascript更改元素的属性值
- 15. 如何使用javascript更改asp.net文本框的文本属性
- 16. 如何使用jQuery更改属性?
- 17. 用户如何更改div的z-index?
- 18. 使用属性网格更改属性
- 19. 如何使用javascript更改表格显示属性
- 20. 如何使用JavaScript更改输入名称属性值
- 21. 如何使用javascript更改iframe基本属性
- 22. 基本javascript用户输入更改div
- 23. 更改FB用户对象的属性
- 24. 如何用Javascript更改div位置?
- 25. 如何用javascript更改div内容?
- 26. 如何使用.properties文件更改ant属性位置属性
- 27. 如何使用c改变用户控件的div可见性#
- 28. 使用UserPrincipal更改AD用户帐户属性
- 29. 如何让“ng-”使用任何属性?
- 30. 如何重用WPF用户控件,但更改绑定属性?
您好,欢迎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