Summary of using jquery

Source: Internet
Author: User

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 );}});};

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.