使用jquery的一些总结
程序员文章站
2022-07-12 12:23:11
...
1,使用jquery获取文本框的值
var abcdefg=$(“#text12”);
方式一:abcdefg[0].value
方式二:abcdefg.val()
注意:abcdefg.attr(“value”)获取的是默认值,而不是当前文本框的值
2,使用jquery设置为只读
方式一:
$('#mechCoupon\\.startNo')[0].readOnly="true";
$('#mechCoupon\\.endNo')[0].readOnly="true";
方式二:
var name22=$('#text1')
name22.attr("readonly",true)
name22.prop("readonly",true)//prop也可以
3,jquery 选中checkbox
$('#checkbox222').attr("checked",true);
取消选中
$('#checkbox222').attr("checked",false);
4,jquery获取元素的data-url属性的值
var videoUrl = that.data('url');
同理,获取data-id的值
var videoUrl = that.data('id');
5,jquery 查询天气预报
var weather_baidu_url = 'http://api.map.baidu.com/telematics/v3/weather';
var ak_baidu = 'qG49xeEochXpAp1WDVzD6wA7';
var weather_query = function (self) {
var $thisForm = com.whuang.hsj.getForm(self);
var $city = $thisForm.find("input[type=text]");
if ($city == '') {
alert("请输入城市");
return;
}
var cityVal = $city.val();
var weather_query_url = weather_baidu_url + '?location=' + cityVal + '&output=json&ak=' + ak_baidu;
var $result_weather_panel = $('#result_weather_panel');
$.jsonP({
url: weather_query_url, success: function (data) {
var htmlFragment = null;
if (data && data.status == 'success') {
var results = data.results[0];
var currentDate = data.date;
var weather_data = results.weather_data;
var currentCity = results.currentCity;
$result_weather_panel.find(('h1')).html(currentCity + '<span style="font-weight: normal;font-size: initial;" >(PM2.5:' + results.pm25 + ')</span>');
var html = [];
var length = weather_data.length;
html.push(getWeatherResultFirstItem(weather_data[0]));
for (var i = 1; i < length; i++) {
html.push(getWeatherResultListItem(weather_data[i]));
}
htmlFragment = html.join('');
$.ui.loadContent('#result_weather_panel', false, false, 'slide');
} else {
alert('没有查询到天气信息');
return;
}
$result_weather_panel.find("ul.list").html(htmlFragment);
user.log('weather:'+cityVal);
}
});
};
上一篇: 监控域名HTTPS证书过期时间
下一篇: 获取免费的证书和域名