关键时间输入的向上箭头

时间:2018-01-19 10:09:02

标签: javascript jquery

我希望#End的值总是等于#Start的值,即使有人只是在没有释放鼠标的#Start上做键盘



// method 1 : this works only with on change not with keyup
$('#start').change(function() {
    $('#end').val($('#start').val())
})

// method 2 : this does not work with keyup at all, donno why
$(document).on('keyup', '#start', function() {
    $('#end').val($('#start').val())
})

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<input type="time" id="start" value="00:00">
<input type="time" id="end" value="00:00">
&#13;
&#13;
&#13;

enter image description here

怎么可能?

2 个答案:

答案 0 :(得分:2)

使用 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="time" id="start" value="00:00"> <input type="time" id="end" value="00:00"> <br><br> <input type="time" id="start1" value="00:00"> <input type="time" id="end1" value="00:00">事件或绑定您想要侦听的所有事件(相当于输入事件,但我认为它更具跨浏览器可靠性):

input
{{1}}

我更喜欢{{1}}事件,因为它会更新每次更改,但正如我所说,跨浏览器......

答案 1 :(得分:0)

尝试使用Click and Keyup,它将起作用

// method : this will works with Click and Keyup events
$('#start').on('click keyup',function() {
    $('#end').val($('#start').val())
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<input type="time" id="start" value="00:00">
<input type="time" id="end" value="00:00">