English 中文(简体)
写多功能的高效方法
原标题:efficicent way to write multiple jquery functions

我有多个编织品,我不得不为每个编目写一个类似的法典,并且通过NBR++美元来改变补贴。 是否有更快的方式来写这番话,而不是让每个小部分都拥有这种独特性?

   // when $NBR = 1
   <div class="playbutton<?php echo $NBR?>">
       <script>
           $(".playbutton<?php echo $NBR?>").click(function()
              {  $(".playbutton<?php echo $NBR?>").hide();
                 $( #songpicture ).attr("src", "<?php echo $thumb[$NBR]?>");
              });
       </script>
   </div>


   // when $NBR = 2
   <div class="playbutton<?php echo $NBR?>">
       <script>
           $(".playbutton<?php echo $NBR?>").click(function()
              {  $(".playbutton<?php echo $NBR?>").hide();
                 $( #songpicture ).attr("src", "<?php echo $thumb[$NBR]?>");
              });
       </script>
   </div>

This goes on 15 times ...etc.....All php variable are set at the beginning of each div with PHP.

因此,我可以把这一内容压缩成一个可以一度书写的法典吗? 或者,在每半天之后必须写出来?

感谢你们的帮助!

最佳回答

删除所有其他文字,

 <script>
  $(function () {
     $(".playback_divs").click(function() {  
       $(this).hide();
       $( #songpicture ).attr("src", $(this).data( thumb-nbr ));
     });
  }
 </script>

页: 1

<div class="playback_divs playbutton<?php echo $NBR?>" data-thumb-nbr="<?php echo $thumb[$NBR]?>">

注 html改动

(1) 添加到div的新类别<代码>。

(2) at数据<代码>数据-thumb-nbr。

问题回答

暂无回答




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签