jquery javascript 常用代码备忘
1.假如页面上有一组radio,初始化页面时,想让指定的radio选中
代码如下:
$("input:radio[name='status']").each(function() { var v = $(this).val();if (v== '1') {$(this).attr("checked", "checked");}});
//初始化日期控件$('#selectDate').datepick({yearRange: '2008:2099', dateFormat: 'yy-mm-dd',prevText:'前一月',nextText:'后一月',closeText:'关闭',clearText:'清除',monthNames:['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月']});
http://api.showji.com/Locating/default.aspx?m=15084975782&output=json&callback=querycallback
querycallback({ "Mobile": "15084975782", "QueryResult": "True", "Province": "湖南", "City": "长沙", "AreaCode": "0731", "PostCode": "410000", "Corp": "中国移动", "Card": "GSM"});
$(".trbox").click(function(){var obj = $(this);var box = obj.find("input:type='checkbox'");if (box.attr('checked')) {box.attr('checked',false);} else {box.attr('checked',true);}});$(".boxClass").click(function(event){ event.stopPropagation(); });
var mod = $(".mod");mod.click(function(){var obj = $(this);var td = obj.parent().parent().children(".inputClass");tdValue = $.trim(td.text());var input = $("<input type='text' style='color:#148CDF;' value='" + tdValue + "' />"); // 文本框的HTML代码td.html(input); // 当前td的内容变为文本框input.click(function() {return false;});// 设置文本框的样式input.height(td.height()-10); //文本框的高度为当前td单元格的高度input.css("margin-left","-3px");input.width("100px"); // 宽度为当前td单元格的宽度input.css("font-size", "12px"); // 文本框的内容文字大小为14pxinput.css("text-align", "center"); // 文本居中});