使用jquery的一些总结
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);
}
});
};
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。