简体   繁体   English

单击按钮复制字段值

[英]Copy value of field with button is clicked

I'm trying to create a simple button using jquery. 我正在尝试使用jquery创建一个简单的按钮。 When the user clicks a button, the value of 'timestart' is copied into 'timeend'. 当用户单击按钮时,“timestart”的值将复制到“timeend”中。

<input id="timestart" name="timestart" value="" /> 
<!-- need button here: Click here to copy/paste value into timeend field -->
<input id="timeend" name="timeend" value="" />

Any help appreciated, thanks! 任何帮助表示感谢,谢谢!

Put a button in there, give it an ID or some other defining characteristic, and simply set the value of timeend when it's clicked. 在其中放置一个按钮,给它一个ID或其他一些定义特征,并在单击时设置timeend的值。 This example assumes some element with an ID of "yourButton": 此示例假设某个元素的ID为“yourButton”:

$("#yourButton").on("click", function () {
    $("#timeend").val($("#timestart").val());
});

References: 参考文献:

This is very simple stuff. 这是非常简单的事情。 I would suggest spending some time reading through the jQuery docs to get an idea of the methods available to you. 我建议花一些时间阅读jQuery文档,以了解可用的方法。

do it like this 像这样做

 $('#btnSubmit')​.click(function(){
        $('#timeend').val($('#timestart').val());
    });

Live Demo 现场演示

HTML HTML

<input id="timestart" name="timestart" value="" />
<button id='copy'>Copy</button>
<input id="timeend" name="timeend" value="" />

jQuery jQuery的

$(function(){
    $("#copy").on("click",function(){
      $("#timeend").val($("#timestart").val())   
    })
})

DEMO DEMO

Try this: 尝试这个:

$('.button').on('click', function(){
    var val = $('#timestart').val();
    $('input#timeend').val(val);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM