2

因为我是 jquery 的新手,所以我不知道我到底在这里做什么,

我有一个名为 frmCustom 的表单,并且有三个文本框

 <form id="frmCustom">

       <input type="text" id="width">
       <input type="text" id="height">
       <input type="text" id="depth">

    </form>

我只想在使用 jquery 输入后立即获取文本框中的三个值

任何帮助都将是可观的,

提前致谢

4

2 回答 2

2

您可以订阅 .change 事件:

$('#frmCustom input[type="text"]').change(function () {
    var width = $('#width').val();
    var height = $('#height').val();
    var depth = $('#depth').val();
});
于 2013-07-06T10:17:36.343 回答
2

你想要这样吗?http://jsfiddle.net/yeyene/Bryrt/3/

$('#frmCustom input').keyup(function() {
    if($(this).attr('id')== 'width') 
        var w = $(this).val();
    if($(this).attr('id')== 'height') 
        var h = $(this).val();
    if($(this).attr('id')== 'depth') 
        var d = $(this).val();

    alert([w,h,d]);
});
于 2013-07-06T10:29:08.870 回答