English 中文(简体)
如何将这些支职职能结合起来?
原标题:How to combine these jquery functions?

是否有办法将这些办法结合起来?

$("#demo1Btn").mopTip({ w :200, style :"overClick", get :"#demo1"});
$("#demo2Btn").mopTip({ w :200, style :"overClick", get :"#demo2"});
$("#demo3Btn").mopTip({ w :200, style :"overClick", get :"#demo3"});
$("#demo4Btn").mopTip({ w :200, style :"overClick", get :"#demo4"});
$("#demo5Btn").mopTip({ w :200, style :"overClick", get :"#demo5"});

Thnx

最佳回答
for (var i = 1; i < 6; i++) {
  $("#demo" + i + "Btn").mopTip({ w :200, style :"overClick", get :"#demo" + i});
}

比较清洁

问题回答

是的,你可以把所有班级/班级安排在同一职能上,但只是与 com分开。

$("#demo1Btn, #demo2Btn, #demo3Btn, #demo4Btn, #demo5Btn").mopTip({ w :200, style :"overClick", get :$(this).attr( id ).replace( Btn ,  )});

This should work!

明显有:

$( div[id^="demo"][id$="Btn"] ).mopTip({ w :200, style :"overClick", get :this.id});

将选择<代码>id从“demo”开始、以“btn”结束、this.id 应找到相关要素<代码>id,并将之分派至get参数。

Use the starts-with selector and an each loop

$("[id^= demo ]").each(function(){
    $(this).mopTip({ w :200, style :"overClick", get :"#demo1"});
});




相关问题
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: &...