Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用按钮更改文本输入_Javascript_Jquery_Html - Fatal编程技术网

Javascript 使用按钮更改文本输入

Javascript 使用按钮更改文本输入,javascript,jquery,html,Javascript,Jquery,Html,我正在尝试创建一个函数,这样当我的一个按钮被按下时,文本输入的值就会变为按下的按钮的值 <div id="viewer"> <h1> <input type="text" id="Screen" maxlength="8" value="0"/> </h1> <h2> <button type="button" value="1" id="1">1</button> <button type="butto

我正在尝试创建一个函数,这样当我的一个按钮被按下时,文本输入的值就会变为按下的按钮的值

<div id="viewer">
<h1>
<input type="text" id="Screen" maxlength="8" value="0"/>
</h1>

<h2>
<button type="button" value="1" id="1">1</button>
<button type="button" value="2" id="2">2</button>
</h2>
</div>

我想你换了身份证,还需要换一些别的东西

$(文档).ready(函数(){
$(“按钮”)。单击(函数(){
var val=$(this.val()
$(“#屏幕”).val(val);
警报(val);
onclick=“sevenClick()”;
});
});

1.
2.

使用
保留实际按钮值:

$(文档).ready(函数(){
$(“按钮”)。单击(函数(){
var$val=$(this.val();
//警报(val);
$('屏幕').val($val);
});
});

1.
2.

只需获取按钮的值并将其设置到输入框中即可

$(document).ready(function() {
    $("button").click(function() {
        var butVal = $(this).val(); //get current button value here 
        $("#Screen").text(butVal); // set button value to the textbox
    });
});

很抱歉,我不得不编辑它几次,一些打字错误,试试看它是否有效:)
$(document).ready(function() {
    $('button').click(function() {
        var test = $(this).attr('value');
        $('#Screen').val(test);
    });
});
$(document).ready(function() {
    $("button").click(function() {
        var butVal = $(this).val(); //get current button value here 
        $("#Screen").text(butVal); // set button value to the textbox
    });
});