Javascript jQuery:选择特定单选按钮时,是否按类更新span标记?
选择特定单选按钮时,如何更新标记class=“able” 步骤: 页面打开span class able被清除。 每当选择radio1、radio2或radio3时: 如果已选择radio1,则span class=“able”将使用输入主机1的值进行更新。 如果已选择radio2,span class=“able”将使用输入host2的值进行更新。 如果已选择radio3,则span class=“able”将使用输入host3的值进行更新 提前谢谢你Javascript jQuery:选择特定单选按钮时,是否按类更新span标记?,javascript,jquery,dynamic,radio,Javascript,Jquery,Dynamic,Radio,选择特定单选按钮时,如何更新标记class=“able” 步骤: 页面打开span class able被清除。 每当选择radio1、radio2或radio3时: 如果已选择radio1,则span class=“able”将使用输入主机1的值进行更新。 如果已选择radio2,span class=“able”将使用输入host2的值进行更新。 如果已选择radio3,则span class=“able”将使用输入host3的值进行更新 提前谢谢你 <html lang="e
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>jQuery Update span by radio button selection</title>
<link rel="stylesheet" href="themes/base/jquery.ui.all.css">
<script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script>
<script src="js/jquery-1.6.2.min.js"></script>
<script src="ui/jquery.ui.core.js"></script>
<script src="ui/jquery.ui.datepicker.js"></script>
<script>
</script>
</head>
<body>
<div>
<input type="text" id="host1" value="Able">
<input type="text" id="host2" value="Baker">
<input type="text" id="host3" value="Charlie"><br>
<label><input type="radio" name="radiogroup" value="yes" id="radio1" />Yes</label>
<label><input type="radio" name="radiogroup" value="no" id="radio2" />No</label>
<label><input type="radio" name="radiogroup" value="maybe" id="radio3" />Maybe</label>
<br>
</div>
<span id="result1" class="able"> </span><br>
<span id="result2" class="able"> </span><br>
<span id="result3" class="able"> </span>
</body>
</html>
jQuery通过单选按钮选择更新范围
对
不
大概
您可能希望将单击事件添加到单选按钮中,onclick会更改跨距的值
比如:
$('#radio1').click(function(){$('span.able').html($('#host1').val());});
您还可以使其更常见:
$('input:radio').live('click',function(){
var jThis = $(this), jText = $('#'+jThis.attr('text_id'));
$('span.able').html(jText.val());
});
您需要在单选按钮中添加一个属性“text\u id”,以标识给定单选按钮应使用的文本。试试这个
$('input:radio').click(function(){
var id = this.id.replace('radio', '');
$('#result' + id).text($('#host' + id).val());
});
工作