Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.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
JQuery选择单选按钮旁边的文本_Jquery_Replace_Radio Button_Checked - Fatal编程技术网

JQuery选择单选按钮旁边的文本

JQuery选择单选按钮旁边的文本,jquery,replace,radio-button,checked,Jquery,Replace,Radio Button,Checked,我需要一些帮助。我有一个div,里面有一些动态生成的单选按钮,每个单选按钮旁边都有一段文本,在一个元素中动态生成,如下所示: <div class="mother_div"> <input type="radio" class="child_radio" name="amount" value="0" /> <span class="child_text">0.0 some text</span> <input type=

我需要一些帮助。我有一个div,里面有一些动态生成的单选按钮,每个单选按钮旁边都有一段文本,在一个元素中动态生成,如下所示:

<div class="mother_div"> 
   <input type="radio" class="child_radio" name="amount" value="0" />
   <span class="child_text">0.0 some text</span>
   <input type="radio" class="child_radio" name="amount" value="1" />
   <span class="child_text">1.0 some text</span>
   <input type="radio" class="child_radio" name="amount" value="2" />
   <span class="child_text">2.0 some text</span>
   <input type="radio" class="child_radio" name="amount" value="3" />
   <span class="child_text">3.0 some text</span> 
非常感谢您的任何想法或建议

试试这个

$('div.mother_div input:radio[name="child_radio"]').click(function() {
    var newHTML= "some HTML to insert";
    $(this).next('span.child_text').html(newHTML);
});
$("div.mother_div input").click(function() {
   var newHTML= "some HTML to insert";
   //this will change text next to radio button clicked
   $(this).next('span.child_text').html(newHTML);  

   //this will change text next to all the radio buttons
   $(this).parent().children('span.child_text').html(newHTML);
});
您的选择器无效。您可以在jsFiddle.net上进行检查或演示


希望这对你们有用。

非常感谢,伙计们。我最终使用了阿马尔的解决方案——效果非常好!顺便说一句,如果单击另一个单选按钮,如何使跨度中的HTML恢复为原始?您可以将原始文本和单击的项目存储在某个变量中,并在需要时恢复它。检查。此外,如果您对答案感到满意,请接受答案并阅读
$("div.mother_div input").click(function() {
   var newHTML= "some HTML to insert";
   //this will change text next to radio button clicked
   $(this).next('span.child_text').html(newHTML);  

   //this will change text next to all the radio buttons
   $(this).parent().children('span.child_text').html(newHTML);
});