jquery, js knowledge

jquery selector

Jquery selector requires two backslashes to escape special characters when fetching elements

For example: var orgName=$("#whir$t3198_f4972").val();    

A minor question:

<div style="WIDTH: 100%" id="whir$t3198-whir$t3198_f4972">
    <div class="cls-ui cls-ui-ui207 cls-ui-readonly cls-ui-1003131 cls-print cls-print207 cls-print-1003131">Information Corporation Communications Operations Department</div>

How to change the word'Information Company Communications Operations'with js?

$("#whir\$t3198-whir\$t3198_F4972 "). children (). EQ (0). text (" Marketing Development Department ");
 This is an error, so you can't get a jquery object

$("div[id='whir$t3198-whir$t3198_F4972']'. children (). EQ (0). text ("Construction Department"); 
That's right

jquery ajax has questions under ie:

url You cannot carry parameters later. If you carry parameters, you will get an error
//Correct practices
        data: {xmname:name},
        dataType: 'json',


Small details:

1. When jqeury operates on hyperlinks, it is necessary to cancel the default behavior of hyperlinks at the last return false of the code, otherwise the code written earlier may not jump after the page has been executed.

2. ReplceAllInvalid in jquery Only the replace method can replace the specified string

3. Differences between attr and prop in jquery
   attr and prop are both methods of getting object properties in jquery

       For the inherent properties of HTML elements themselves, use the prop method when processing.
     For our own custom DOM attributes of HTML elements, use the attr method when processing them.        

Common js tips

1,js To determine if strings are equal and indexOf()Method

    //There is no equals() method in js or jquery to determine whether strings are equal.Direct==is OK;
    js In==Not and java Inside==Similarly compare the memory addresses of objects;
    js In==Will be judged by type and value;Equal if both types and values are equal;If the types are different, the js Try type conversion and compare;

    indexOf Method returns the position of the first occurrence of a specified string value in a string.
    //Return value <0 indicates that the specified string does not exist in the string

2,js Compare Number Sizes
        js The default type in is String Type, if not converted, an error will occur

    var arr = ["a", "b", "c"];
    typeof arr;   // return "object"
    arr  instanceof Array // true
    arr.constructor();  //[]

4,js Strip Spaces
    function String.prototype.Trim() { return this.replace(/(^/s*)|(/s*$)/g, ""); } // Remove left and right spaces

    function String.prototype.Ltrim() { return this.replace(/(^/s*)/g, ""); } // Remove left space

    function String.prototype.Rtrim() { return this.replace(/(/s*$)/g, ""); }  // Remove right space

5,Verify that the parameter is a number

    function isNumber(n){
        return !isNaN(parseFloat(n)) && isFinite(n);

6,Gets the maximum and minimum values of an array of numbers
    var  numbers = [5, 458 , 120 , -215 , 228 , 400 , 122205, -85411];
    var maxInNumbers = Math.max.apply(Math, numbers);
    var minInNumbers = Math.min.apply(Math, numbers);

7,Empty an array
    var  numbers = [5, 458 , 120 , -215 , 228 , 400 , 122205, -85411];
    var maxInNumbers = Math.max.apply(Math, numbers);
    var minInNumbers = Math.min.apply(Math, numbers);

jquery tips

1,Select or uncheck all check boxes on the page    
    var flag = false; 
    $('a').click(function() {
        flag = !flag;

2,Disable Enter Key in Form

    $("#form").keypress(function(e) {
      if (e.which == 13) {
        return false;

3,Clear all form data (666666666666)

    function clearForm(form) {
      $(':input', form).each(function() {
        var type = this.type;
        var tag = this.tagName.toLowerCase(); 
        if (type == 'text' || type == 'password' || tag == 'textarea')
          this.value = "";
        else if (type == 'checkbox' || type == 'radio')
          this.checked = false;
        else if (tag == 'select')
          this.selectedIndex = -1;

4,Disabling and enabling buttons in forms

    //Disable buttons: $("#somebutton").attr("disabled", true);

    //Start button: $("#submit-button").removeAttr("disabled");    

5,Highlight the input box label that is currently focused

    $("form :input").focus(function() {
      $("label[for='" + this.id + "']").addClass("labelfocus");
    }).blur(function() {

6,Dynamically adding form elements

    $('#password1').change(function() {
        $("#password1").append("<input type='text' name='password2' id='password2' />");

Tags: JQuery IE JSON Java

Posted on Thu, 02 Jul 2020 10:44:13 -0400 by Tchelo