我试图做一个小函数来计算图像的重新大小值:
索引.php
<?php
list($width, $height, $type, $attr) = getimagesize("image.jpeg");
echo '<form id="dimensions" action=''>';
echo '<input type="text" class="input1" id="width" value="' . $width . '" onchange="widthfunc()"/>';
echo '<input type="text" class="input1" id="height" value="' . $height . '" onchange="heightfunc()"/>';
echo '<input type="text" class="input1" id="resize" value="' . $resize . '%" onchange="resizefunc()"/>';
echo '<input type="submit" value="change" name="change"/>';
echo '</form>';
?>
网站.js
function widthfunc()
{
var x=document.dimensions.getElementById("height");
var y=document.dimensions.getElementById("width");
var z=document.dimensions.getElementById("resize");
var a = 1280;
var b = 1024;
var c = 100;
x.value=y.value * b / a;
z.value=(a*b)/(x.value*y.value);
}
function heightfunc()
{
var x=document.dimensions.getElementById("height");
var y=document.dimensions.getElementById("width");
var z=document.dimensions.getElementById("resize");
var a = 1280;
var b = 1024;
var c = 100;
x.value=y * b / a;
z.value=(a*b)/(x*y);
}
function resizefunc()
{
var x=document.dimensions.getElementById("height");
var y=document.dimensions.getElementById("width");
var z=document.dimensions.getElementById("resize");
var a = 1280;
var b = 1024;
var c = 100;
x.value=y * b / a;
z.value=(a*b)/(x*y);
}
好吧,默认情况下,该值应该是图像的原始值,除非用户更改了其中一个字段宽度高度或大小(以 % 为单位),我希望 javascript 会更改其他 2 个值...