/***************************by
garcon1986********************************/
ajax1.js
$(function(){ //$(function(){}) equals to $(document).ready(function(){}), equals to $().ready(function(){})
$("#button_check").click(function(){ //define click event of #button_check element
var var_name = $("input[name='radio1']:checked").val(); //define a variable var_name
//input element whose name property equals radio1 and which is selected, we get its value
$('#btn_get').val(var_name); //assign this value to the element whose id is 'btn_get'
});
});
ajax.php
<html>
<head>
<mce:script src="jquery-1.4.js" mce_src="jquery-1.4.js"></mce:script>
<mce:script type="text/javascript" src="ajax1.js" mce_src="ajax1.js" ></mce:script>
</head>
<body>
<input type="radio" value="Blue" name="radio1">Blue</input>
<input type="radio" value="White" name="radio1">White</input>
<input type="radio" value="Red" name="radio1">Red</input>
<input id="button_check" type="button" value="Click" name="btn"></input>
<br />
<input id="btn_get" type="text" name="get_btn_value"></input>
</body>
</html>
jQuery获得radio按钮的值
最新推荐文章于 2025-12-15 15:15:21 发布
本文介绍了一个简单的Ajax应用示例,通过JavaScript实现单击按钮获取选中单选按钮的值,并显示在一个文本框内。该示例使用了jQuery简化Ajax操作。
157

被折叠的 条评论
为什么被折叠?



