jQuery为元素设置自定义维度

Kyl*_*yle 2 html javascript jquery dimensions

我有一个div,我想用两个文本输入设置自定义尺寸.

<div id="theFrame"></div>
    width: <input id="custWidth" type="text">
    height: <input id="custHeight" type="text">
<br>
<button id="custSet">Set my width!</button>
Run Code Online (Sandbox Code Playgroud)

我尝试用变量设置高度和宽度,但我现在不知道如何做到这一点.

var frame = $('div#theFrame');

$("#custWidth")
    .keyup(function () {
        var custWidth = $(this).attr('value');
    })
    .keyup();

$("#custHeight")
    .keyup(function () {
        var custHeight = $(this).attr('value');
    })
    .keyup();

$('#custSet')
    .click( function() {
        frame.css({height: custHeight, width: custWidth});
    });
Run Code Online (Sandbox Code Playgroud)

谢谢.

http://jsfiddle.net/Kyle_Sevenoaks/6MUuv/

ncr*_*ins 5

var frame = $('div#theFrame');
var custWidth;
var custHeight;
$("#custWidth").keyup(function () {
      custWidth = $(this).attr('value');
    }).keyup();

$("#custHeight").keyup(function () {
      custHeight = $(this).attr('value');
    }).keyup();

$('#custSet').click( function() {
    frame.css({height: custHeight, width: custWidth});
});
Run Code Online (Sandbox Code Playgroud)

您的变量范围已关闭.