我有一个jQuery星评级。我的要求是点击按钮获取星号值。
这是我的代码
<div id="Ratingdiv">
<input type="radio" class="star" name="dynamic-control" value="1" />
<input type="radio" class="star" name="dynamic-control" value="2" />
<input type="radio" class="star" name="dynamic-control" value="3" />
<input type="radio" class="star" name="dynamic-control" value="4" />
<input type="radio" class="star" name="dynamic-control" value="5" />
</div>
<div style="padding: 20px">
<form name="html-test" id="html-test">
<input type="button" value="Insert control" onclick="insert_dynamic_control(this.form);" />
<div class="controls" style="padding: 5px; clear: both;">
</div>
<div style="padding: 5px; clear: both;">
<input id="Button1" type="button" onclick="Getval();" value="button" />
<span></span>
</div>
</form>
</div>
点击时使用的jQuery是
<script type="text/javascript">
{
function Getval() {
(function($) {
$().ready(function() {
var main = $('#Ratingdiv');
main.each(function() {
var odds = $(main).find('.star');
alert(odds);
});
});
})(jQuery);
}
我在警告框中未定义。请帮助我
答案 0 :(得分:1)
检查演示
http://jsfiddle.net/sandeepscet/NEEEB/2/
$('#Button1').click(function(){
alert( $('input:radio[name=dynamic-control]:checked').val());
});
答案 1 :(得分:1)
$(function() {
$('#Button1').on('click', function(e){
var main = $('#Ratingdiv');
main.each(function() {
var odds = $(main).find('.star:checked').val();
alert(odds);
});
});
});