About jq delegate

Source: Internet
Author: User
{Code...} I used the on Method. Why did I click it? But what about delegate? Is it because this class is written in php and on cannot be read? Or what?
// PHP
      
  • Categories
  • "; If (mysqli_num_rows ($ run_query)> 0) {while ($ row = mysqli_fetch_array ($ run_query) {$ cid = $ row [" cat_id "]; $ cat_name = $ row ["cat_title"]; // here echo"
  • $ Cat_name
  • ";} Echo"

    ";}} If (isset ($ _ POST [" brand "]) {$ brand_query =" SELECT * FROM brands "; $ run_query = mysqli_query ($ con, $ brand_query); echo"

  • Brands
  • "; If (mysqli_num_rows ($ run_query)> 0) {while ($ row = mysqli_fetch_array ($ run_query) {$ bid = $ row [" brand_id "]; $ brand_name = $ row ["brand_title"]; echo"
  • $ Brand_name
  • ";} Echo"

    ";}} If (isset ($ _ POST [" getProduct "]) {$ product_query =" SELECT * FROM products order by rand () LIMIT "; $ run_query = mysqli_query ($ con, $ product_query); if (mysqli_num_rows ($ run_query)> 0) {while ($ row = mysqli_fetch_array ($ run_query )) {$ pro_id = $ row ['product _ id']; $ pro_cat = $ row ['product _ cat']; $ pro_brand = $ row ['product _ Brand']; $ pro_title = $ row ['product _ title']; $ pro_price = $ row ['product _ price']; $ pro_image = $ row ['product _ image']; echo"

    $ Pro_title

    $. $ Pro_price.00AddToCart

    ";}}?>
    // JS $ (document ). ready (function () {cat (); brand (); product (); function cat () {$. ajax ({url: 'Action. php ', type: 'post', data: {category: 1 },}). done (function (data) {// console. log (data); $ ("# get_category" ).html (data) ;});} function brand () {$. ajax ({url: 'Action. php ', type: 'post', data: {brand: 1 },}). done (function (data) {// console. log (data); $ ("# get_brand" ).html (data) ;});} function p Roduct () {$. ajax ({url: 'Action. php ', type: 'post', data: {getProduct: 1 },}). done (function (data) {// console. log (data); $ ("# get_product" ).html (data) ;});} // use the delegate () method. On cannot get $ ("body "). delegate (". category "," click ", function () {alert (123) ;}) // $ (". category "). on ("click", function (event) {// alert (13 );//});})

    Why didn't I respond when I clicked on the on method? But what about delegate? Is it because this class is written in php and on cannot be read? Or what?

    Reply content:
    // PHP
          
  • Categories
  • "; If (mysqli_num_rows ($ run_query)> 0) {while ($ row = mysqli_fetch_array ($ run_query) {$ cid = $ row [" cat_id "]; $ cat_name = $ row ["cat_title"]; // here echo"
  • $ Cat_name
  • ";} Echo"

    ";}} If (isset ($ _ POST [" brand "]) {$ brand_query =" SELECT * FROM brands "; $ run_query = mysqli_query ($ con, $ brand_query); echo"

  • Brands
  • "; If (mysqli_num_rows ($ run_query)> 0) {while ($ row = mysqli_fetch_array ($ run_query) {$ bid = $ row [" brand_id "]; $ brand_name = $ row ["brand_title"]; echo"
  • $ Brand_name
  • ";} Echo"

    ";}} If (isset ($ _ POST [" getProduct "]) {$ product_query =" SELECT * FROM products order by rand () LIMIT "; $ run_query = mysqli_query ($ con, $ product_query); if (mysqli_num_rows ($ run_query)> 0) {while ($ row = mysqli_fetch_array ($ run_query )) {$ pro_id = $ row ['product _ id']; $ pro_cat = $ row ['product _ cat']; $ pro_brand = $ row ['product _ Brand']; $ pro_title = $ row ['product _ title']; $ pro_price = $ row ['product _ price']; $ pro_image = $ row ['product _ image']; echo"

    $ Pro_title

    $. $ Pro_price.00AddToCart

    ";}}?>
    // JS $ (document ). ready (function () {cat (); brand (); product (); function cat () {$. ajax ({url: 'Action. php ', type: 'post', data: {category: 1 },}). done (function (data) {// console. log (data); $ ("# get_category" ).html (data) ;});} function brand () {$. ajax ({url: 'Action. php ', type: 'post', data: {brand: 1 },}). done (function (data) {// console. log (data); $ ("# get_brand" ).html (data) ;});} function p Roduct () {$. ajax ({url: 'Action. php ', type: 'post', data: {getProduct: 1 },}). done (function (data) {// console. log (data); $ ("# get_product" ).html (data) ;});} // use the delegate () method. On cannot get $ ("body "). delegate (". category "," click ", function () {alert (123) ;}) // $ (". category "). on ("click", function (event) {// alert (13 );//});})

    Why didn't I respond when I clicked on the on method? But what about delegate? Is it because this class is written in php and on cannot be read? Or what?

    Use on for dynamically generated elements

     $('body').on('click','.category' , function() {         alert(123);     })

    Before using a new API, you should fully understand its role through the documentation.

    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.