请教一个简单的JQ问题,望解答

colorbird 2011-11-16 06:11:04
<script language="javascript">
$(document).ready(function(){
//jQuery().checkbox({checked:'checkbox/checked.gif',unchecked:'checkbox/unchecked.gif'});
jQuery().radiobox({checked:'checkbox/checked.gif',unchecked:'checkbox/unchecked.gif'});
$("form").submit( function() {
//这个在jq1.4应该怎么写???
alert(
$("input[@id='box1']")[0].checked + "\n" +
$("input[@id='box2']")[0].checked + "\n" +
$("input[@id='box3']")[0].checked + "\n" +
$("input[@id='box4']")[0].checked
);
return false;
});
});
jQuery.fn.radiobox = function(opt){
jQuery("input:radio").each(function(){
jQuery("<img>")
.attr({src:this.checked ? opt.checked : opt.unchecked})
.bind('click',function(){
jQuery("input:radio").each(function(){
//这行用注释部分会出错???
//jQuery(this).prev()[0].attr('src',opt.u nchecked);
jQuery(this).prev()[0].src = opt.unchecked;
});
var check = jQuery(this).next()[0].checked == true;
jQuery(this)
.attr({src : check ? opt.unchecked : opt.checked})
.next()[0].checked = !check;
})
.insertBefore(this);
});
/*jQuery("input[@type='radio']").hide().each(function(){
jQuery("<img>")
.attr({src:this.checked ? opt.checked : opt.unchecked})
.bind('click',function(){
jQuery("input[@type='radio']").each(function(){
jQuery(this).prev()[0].src = opt.unchecked;
});
var check = jQuery(this).next()[0].checked == true;
jQuery(this)
.attr({src : check ? opt.unchecked : opt.checked})
.next()[0].checked = !check;
})
.insertBefore(this);
});*/
}
</script>
<h3>Example</h3>

<form method="post">
<p><input type="radio" name="box" id="box1"/><label for="box1"> Option 1</label></p>
<p><input type="radio" name="box" id="box2"/> Option 2</p>
<p><input type="radio" name="box" id="box3"/> Option 3</p>
<p><input type="radio" name="box" id="box4"/> Option 4</p>
<input type="submit" value="Show state" />
</form>




主要想处理:
//jQuery(this).prev()[0].attr('src',opt.u nchecked);应该怎么写???
jQuery(this).prev()[0].src = opt.unchecked;

//这个在jq1.4应该怎么写???
alert(
$("input[@id='box1']")[0].checked + "\n" +
$("input[@id='box2']")[0].checked + "\n" +
$("input[@id='box3']")[0].checked + "\n" +
$("input[@id='box4']")[0].checked
);
...全文
100 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
默默不得鱼 2011-11-16
  • 打赏
  • 举报
回复
这代码也够乱的
yhtapmys 2011-11-16
  • 打赏
  • 举报
回复
1.
jQuery(this).prev()[0].attr('src',opt.unchecked);//opt.u nchecked去掉空格


2.
alert($("#box1")[0].checked + "\n" + $("#box2")[0].checked + "\n" + $("#box3")[0].checked + "\n" + $("#box4")[0].checked);
colorbird 2011-11-16
  • 打赏
  • 举报
回复
jQuery(jQuery(this).prev()[0]).attr('src',opt.unchecked);

87,990

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧