Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.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_Textbox - Fatal编程技术网

Javascript 如何根据选择的单选按钮填充文本框?

Javascript 如何根据选择的单选按钮填充文本框?,javascript,jquery,html,textbox,Javascript,Jquery,Html,Textbox,我正在使用html和jquery。我有一个表单,在这个表单中,我几乎没有单选按钮和文本框。我需要根据选择的单选按钮填充文本框 这是我的 现在我需要做的是-选择Process按钮后,如果我选择UpdateTest单选按钮,那么我需要在AddNodeText框中添加hello,但是如果我选择DataTest单选按钮,然后我需要在AddNodeText框中添加world,除此之外,我不需要在AddNodeText框中添加任何内容 使用jquery可以做到这一点吗?您尝试过吗 $('input[name

我正在使用html和jquery。我有一个表单,在这个表单中,我几乎没有单选按钮和文本框。我需要根据选择的单选按钮填充文本框

这是我的

现在我需要做的是-选择
Process
按钮后,如果我选择
UpdateTest
单选按钮,那么我需要在
AddNodeText
框中添加
hello
,但是如果我选择
DataTest
单选按钮,然后我需要在
AddNodeText
框中添加
world
,除此之外,我不需要在
AddNodeText
框中添加任何内容

使用jquery可以做到这一点吗?

您尝试过吗

$('input[name="client"]').click(function() {
    if ($(this).attr('id') === 'updatetest')
    {
        $('#conf').val('hello');
    }
    else if ($(this).attr('id') === 'datatest')
    {
        $('#conf').val('world');
    }
    else
    {
        $('#conf').val('');
    }
});

这是使用数据属性很好地完成的

设置数据属性

<input type="radio" data-text="hello"></input>
这是你的小提琴,我已经更新了它和它的工作

$(".boxes").on('click', function() {
 var text = this.getAttribute('data-text');
 $("input#conf").val(text);
});