js的杂记(一)
1.js中的push和join方法的使用
var selected = new Array();
//push()把一个元素添加到数组的尾部
selected.push(boxes[i].value);
// join()方法将数组中的所有元素转换成字符串,然后连接起来,这刚好和String的split()方法是一个相反的操作。join()默认是使用“,”作为分隔符,当然你也可以在方法中指定分隔符
var idStr = selected.join();
2.radio的选择,checked的定位
|
<input type=”radio” name=”test” title=”男” value=”1” checked> <input type=”radio” name=”test” title=”女” value=”0”> <script> $(function(){ //注意引入jQuery $(“input[name=’test’]:checked”).val();//选中的radio的值 $(“input[name=’test’,value=’男’]”).attr(‘checked’,true);//选中value=’男’的选项 }) </script> |

浙公网安备 33010602011771号