Summary of using jquery
1. Use jquery to obtain the value of the text box.
Var abcdefg = $ ("# text12 ");
Method 1: abcdefg [0]. value
Method 2: abcdefg. val ()
Note: abcdefg. attr ("value") obtains the default value instead of the value of the current text box.
2. Set jquery to read-only
Method 1:
$('#mechCoupon\\.startNo')[0].readOnly="true"; $('#mechCoupon\\.endNo')[0].readOnly="true";
Method 2:
Var name22 = $ ('# text1') name22.attr ("readonly", true) name22.prop ("readonly", true) // prop can also
3. Select checkbox in jquery.
$('#checkbox222').attr("checked",true);
Deselect
$('#checkbox222').attr("checked",false);
4. jquery obtains the data-url attribute value of an element.
var videoUrl = that.data('url');
Similarly, get the data-id value
var videoUrl = that.data('id');
5. query weather forecasts using jquery
Var weather_baidu_url = 'HTTP: // export 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 (" Enter city "); 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; then result_weather_panel.find('h1'{}.html (currentCity + '(PM2.5:' + results. pm25 + '); 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 ('Weather info not found '); return;} $ result_weather_panel.find ("ul. list "cmd.html (htmlFragment); user. log ('Weather: '+ cityVal );}});};