开发者

In onclick event I want the pass the variable to div (I'm using single div)

开发者 https://www.devze.com 2022-12-20 12:21 出处:网络
In onclick event how to pass the variable to div, using that variable I want display the values in t开发者_运维百科he div.If you use jQuery, it\'s better to use jQuery metadata plugins. You can put an

In onclick event how to pass the variable to div, using that variable I want display the values in t开发者_运维百科he div.


If you use jQuery, it's better to use jQuery metadata plugins. You can put any value into a DOM element inside the class attribute. Here is the example:

<div id="some_div_id" class"default {'id': '2', 'type': 'general'}">
  div content here...
</div>

<script type="text/javascript">
jQuery(function($){
  $("#some_div_id").click(function(){
    var data = $(this).metadata();
    //now you can access the variable, example:
    console.log(data.id);  //you will get 2 in Firebug
    console.log(data.type);  //you will get 'general' in Firebug
    //do some processing here...
    //...
  });
});
</script>

When writing the div, you can put value from the php easily:

<div id="some_div_id" class"default {'id': '<?php echo $id; ?>', 'type': '<?php echo $type; ?>'}">

I hope this is what you looking for.

jQuery is a cross browser javascript library. It will save you from writing a complex javascript code that will run in all modern browser.

0

精彩评论

暂无评论...
验证码 换一张
取 消