I have a code here:
<script type="text/javascript" src="<?=base_url()?>lib/jquery-1.6.2.min.js"></script>
<script type="text/javascript">
$('.hover-star').click(function (){
$('.someDiv').text(this.val());
})
</script>
<input name="neat" type="radio" class="hover-star" value="1" title="Poor"/>
<input name="nea开发者_StackOverflow中文版t" type="radio" class="hover-star" value="2" title="Fair"/>
<input name="neat" type="radio" class="hover-star" value="3" title="Satisfactory"/>
<input name="neat" type="radio" class="hover-star" value="4" title="Outstanding"/>
<div id="someDiv">aray</div>
My problem here is that it isn't throwing anything! I'm really in the corner here. In jsfiddle.net this is working. What I want is when my radio button is clicked it will show its value or title.
I see four things in your code:
Don't forget the
;
at the end of your jquery click event definition.You should use
#someDiv
instead of.someDiv
as someDiv is an Object Id, not a Object class. This was already mentioned by Wesley.You can't use
this.val()
sinceval()
is not a native javascript function. You may want to use$(this).val()
which is wrapping the javascript object into jQuery.You need to use
$(function() { /* your code */ });
as your javascript function is defined before your HTML object will be created. This is a shortcut for$(document).ready(function () { /* your code */ });
It would be:
<script type="text/javascript">
$(function() {
$('.hover-star').click(function (){
$('#someDiv').text($(this).val());
});
});
</script>
You need to put your jQuery code in the "ready" handler:
$(document).ready(function() {
// put your jQuery code here.
});
You should use $(this)
, not this
.
See here.
精彩评论