求助:一个字符转义的问题! 本帖最后由 ask00000001 于 2011-10-21 09:26:08 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这样写呢?var p = ["picValue","..."]for(var i= 0;i<p.length;i++){var objname = ":radio[name='"+p[0]+"']:first";$(objname).attr("checked",true);} var p = ["picValue","..."]for(var i= 0;i<p.length;i++){$(":radio[name='"+p[i]+"']:first").attr("checked",true);} 这个貌似用 eval()处理可以 $(function(){ var arr = ["picValue","gpsValue"]; for(var i=0;i<arr.length;i++){ $(":checkbox:#'"+arr[i]+"'").click(function() { //这里以前的写法是$(":checkbox:#picValue") if($(this).attr("checked") == false){ $(":radio[name='"+arr[i]+"']").attr("checked",false); }else{ $(":radio[name='picValue']:first").attr("checked",true); //这里的picValue我想用arr[0]替换 } }); } });是这样的! $(":checkbox:#'"+arr[i]+"'")==》$("#"+arr[i])完毕 把 $(":radio[name='picValue']:first").attr("checked",true);中的picValue用arr[i]替换该如何替换 $(":radio[name='"+arr[i]+"']").attr("checked",true);上面这种方式不正确,请给出正确的方式 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gbk"> <title>Untitled Document</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> <script type="text/javascript"> //radio的值 var radio_value = 'loveu'; //checkbox的值,缺少is_3 var checkbox_value = new Array("is_1","is_2","is_4","is_5","is_6"); $(function(){ //首先,这个radio每次只能选择一个 $(":radio[name='"+radio_value+"']:first").attr("checked",true); //checkbox的选择 $.each(checkbox_value,function(index,el){ $(":checkbox[name='"+el+"']:first").attr("checked",true); }); }); </script> </head> <body> <br> <input type="radio" name="love" value="01">爱 <input type="radio" name="love" value="02">不爱 <input type="radio" name="love" value="03">可以爱 <input type="radio" name="love" value="04">还是爱 <input type="radio" name="love" value="05">最终爱 <input type="radio" name="love" value="06">不得爱 <br> <input type="radio" name="loveu" value="01">爱u <input type="radio" name="loveu" value="02">不爱u <input type="radio" name="loveu" value="03">可以爱u <input type="radio" name="loveu" value="04">还是爱u <input type="radio" name="loveu" value="05">最终爱u <input type="radio" name="loveu" value="06">不得爱u <br> <input type="checkbox" name="is_1" value="01">爱u <input type="checkbox" name="is_2" value="02">不爱u <input type="checkbox" name="is_3" value="03">可以爱u <input type="checkbox" name="is_4" value="04">还是爱u <input type="checkbox" name="is_5" value="05">最终爱u <input type="checkbox" name="is_6" value="06">不得爱u </body></html> $(":checkbox[name='"+el+"']").attr("checked",true);去掉:first就行,这里没必要用 楼主是不是把p[i]写成p[0]了? <html> <head> <title>测试JavaScript</title> <script type="text/javascript" src="jquery-1.6.1.js"></script> <script type="text/javascript"> $(function(){ var arr = ["picValue","gpsValue"]; for(var i=0;i<arr.length;i++){ $("#"+arr[i]+":checkbox").click(function() { if(!$(this).attr("checked")){ $(":radio[name='"+this.id+"']").attr("checked",false); }else{ $(":radio[name='"+ arr[0] + "']").attr("checked",true); //这里的picValue我想用arr[0]替换 } }); } }); </script> </head> <body> <input type="checkbox" id="picValue" /> <input type="checkbox" id="gpsValue" /> <input type="radio" name="picValue" /> <input type="radio" name="gpsValue" /> </body></html>这样呢? var p = ["picTest","..."]$(":radio:#'"+p[0]+"':first").attr("checked",true) $(function() { var p = ['Rd0', 'Rd1']; for (var i = 0; i < p.length; i++) { $(":radio[name='" + p[i] + "']:first").attr('checked', 'checked'); } }) 没有问题吧.<html><head><script type="text/javascript" src="jquery/jquery.js"></script><script type="text/javascript">$(document).ready(function(){ $(":button").click(function(){ var p = ["a1","a2","a3"] for(var i= 0;i<p.length;i++){ $(":radio[name='"+p[i]+"']").attr("checked",true); } });});</script></head><body><p>If you click on me, I will disappear.</p><input type='radio' name='a1' >a1<br><input type='radio' name='a2' >a1<br><input type='radio' name='a3' >a1<br><button>choose</button></body></html> ie6下文本框光标不见 为什么不显示啊? 请问南方人才网上那个职位搜索的弹出窗口是怎么做的啊? Javascript如何实现内嵌HTML代码 关于图片长度,不好解决 100分,提示缺少函数,还请帮忙 如何在JS里给FILE类型的表单付值 请教如何使一个列表框动态获取另一个列表框的onChange事件?吐血求助!!!请大家一定帮忙!!! 如何判断光标是在文本框中字符串在第一个字符的前面,还是最后一个字符的后面,有用立即给分. 请教,还是在textarea里,控制光标的问题。谢谢 问一个jq的正则提取字符问题 新手求教育,那位大哥帮我看下什么问题
这样写呢?
var p = ["picValue","..."]for(var i= 0;i<p.length;i++){
var objname = ":radio[name='"+p[0]+"']:first";
$(objname).attr("checked",true);
}
}
$(function(){
var arr = ["picValue","gpsValue"];
for(var i=0;i<arr.length;i++){
$(":checkbox:#'"+arr[i]+"'").click(function() {
//这里以前的写法是$(":checkbox:#picValue")
if($(this).attr("checked") == false){
$(":radio[name='"+arr[i]+"']").attr("checked",false);
}else{
$(":radio[name='picValue']:first").attr("checked",true);
//这里的picValue我想用arr[0]替换
}
});
}
});
是这样的!
==》
$("#"+arr[i])完毕
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>Untitled Document</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
//radio的值
var radio_value = 'loveu';
//checkbox的值,缺少is_3
var checkbox_value = new Array("is_1","is_2","is_4","is_5","is_6");
$(function(){
//首先,这个radio每次只能选择一个
$(":radio[name='"+radio_value+"']:first").attr("checked",true);
//checkbox的选择
$.each(checkbox_value,function(index,el){
$(":checkbox[name='"+el+"']:first").attr("checked",true);
});
});
</script>
</head>
<body>
<br>
<input type="radio" name="love" value="01">爱
<input type="radio" name="love" value="02">不爱
<input type="radio" name="love" value="03">可以爱
<input type="radio" name="love" value="04">还是爱
<input type="radio" name="love" value="05">最终爱
<input type="radio" name="love" value="06">不得爱
<br>
<input type="radio" name="loveu" value="01">爱u
<input type="radio" name="loveu" value="02">不爱u
<input type="radio" name="loveu" value="03">可以爱u
<input type="radio" name="loveu" value="04">还是爱u
<input type="radio" name="loveu" value="05">最终爱u
<input type="radio" name="loveu" value="06">不得爱u
<br>
<input type="checkbox" name="is_1" value="01">爱u
<input type="checkbox" name="is_2" value="02">不爱u
<input type="checkbox" name="is_3" value="03">可以爱u
<input type="checkbox" name="is_4" value="04">还是爱u
<input type="checkbox" name="is_5" value="05">最终爱u
<input type="checkbox" name="is_6" value="06">不得爱u
</body>
</html>
去掉:first就行,这里没必要用
<html>
<head>
<title>测试JavaScript</title>
<script type="text/javascript" src="jquery-1.6.1.js"></script>
<script type="text/javascript">
$(function(){
var arr = ["picValue","gpsValue"];
for(var i=0;i<arr.length;i++){
$("#"+arr[i]+":checkbox").click(function() {
if(!$(this).attr("checked")){
$(":radio[name='"+this.id+"']").attr("checked",false);
}else{
$(":radio[name='"+ arr[0] + "']").attr("checked",true);
//这里的picValue我想用arr[0]替换
}
});
}
}); </script>
</head>
<body>
<input type="checkbox" id="picValue" />
<input type="checkbox" id="gpsValue" />
<input type="radio" name="picValue" />
<input type="radio" name="gpsValue" />
</body>
</html>这样呢?
$(":radio:#'"+p[0]+"':first").attr("checked",true)
$(function() {
var p = ['Rd0', 'Rd1'];
for (var i = 0; i < p.length; i++) {
$(":radio[name='" + p[i] + "']:first").attr('checked', 'checked');
}
})
<html><head>
<script type="text/javascript" src="jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(":button").click(function(){
var p = ["a1","a2","a3"] for(var i= 0;i<p.length;i++){ $(":radio[name='"+p[i]+"']").attr("checked",true);
} });
});
</script>
</head><body>
<p>If you click on me, I will disappear.</p>
<input type='radio' name='a1' >a1<br>
<input type='radio' name='a2' >a1<br>
<input type='radio' name='a3' >a1<br>
<button>choose</button>
</body></html>