我想使用输入控件动态地操作元素。纯JavaScript或jQuery都可以。
src="https://www.w3schools.com/css/rock600x400.jpg" >
</br><br>
<form class="button" action="">
Width
<input class="button" type="number" value="300">
Height
<input class="button" type="number" value="400">
</form>
结果将是这样的:
答案 0 :(得分:1)
您要做的就是添加一些id
属性,在JavaScript中引用您的元素,并更新图像样式oninput
(更改宽度或高度的值)>
let img = document.getElementById('img');
let width = document.getElementById('width');
let height = document.getElementById('height');
changeSize = () => {
img.style.width = `${width.value}px`;
img.style.height = `${height.value}px`;
}
<img id="img" src="https://www.w3schools.com/css/rock600x400.jpg" />
</br><br>
<form class="button" action="">
Width
<input id="width" class="button" type="number" value="300" oninput="changeSize()"> Height
<input id="height" class="button" type="number" value="400" oninput="changeSize()">
</form>