On the delegate problem of JQ

Source: Internet
Author: User
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"];//problem 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_i D "]; $brand _name = $row ["Brand_title"]; echo "
  • $brand _name
  • "; } echo ""; }}if (Isset ($_post["getproduct"])) {$product _query = "SELECT * FROM Products ORDER by RAND () LIMIT 0,9"; $run _query = Mysqli_query ($con, $product _query); if (Mysqli_num_rows ($run _query) >0) {while ($row = Mysqli_fetch_array ($run _query)) {$pro _id = $row [' Pro Duct_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 product () {$.ajax ({url: ' action.php ', type: ' POST ', Da TA: {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); // });})

    I use on the method why click No response? And delegate has it? Is it because this class is written on 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"];//problem 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_i D "]; $brand _name = $row ["Brand_title"]; echo "
  • $brand _name
  • "; } echo ""; }}if (Isset ($_post["getproduct"])) {$product _query = "SELECT * FROM Products ORDER by RAND () LIMIT 0,9"; $run _query = Mysqli_query ($con, $product _query); if (Mysqli_num_rows ($run _query) >0) {while ($row = Mysqli_fetch_array ($run _query)) {$pro _id = $row [' Pro Duct_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 product () {$.ajax ({url: ' action.php ', type: ' POST ', Da TA: {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); // });})

    I use on the method why click No response? And delegate has it? Is it because this class is written on PHP and on cannot be read? Or what?

    Use on for dynamically generated elements

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

    Before you use a new API, you should fully understand its usefulness through 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.