English 中文(简体)
我如何获得积极案文
原标题:How do I get the text of the active
  • 时间:2010-09-21 12:23:20
  •  标签:
  • jquery
<div class="tabs">
<ul>
  <li class="active"><span class="l"></span><a href="#">Standard Class</a><span class="r"> </span></li>
<li><span class="l"></span><a href="#">Bussiness Class</a><span class="r"></span></li>
<li><span class="l"></span><a href="#">Premium</a><span class="r"></span></li>

以及我如何从非选中选取的班级,将其放在选修课上

最佳回答
$( .tabs a ).click(function() { 
 $( .tabs li ).removeClass( active );
 (this).parent().addClass( active );
});

积极案文:

$ ( .tabs .active a ).text();

问题回答

为此:

它预示着你的<代码><li>内容,因此,你无需从OMM中挑选这些内容。

var $lis = $( div.tabs > ul > li ).click(function() {
    var text = $(this).addClass( active ).text();
    $lis.not(this).removeClass( active );
});
var activeText = $( .active a ).text();

Live example: http://jsbin.com/uwigo4/3 (资料来源如下)

查阅“活性”文本,请使用text:

var text = $( div.tabs li.active ).text();

正在做的改动是:http://api.jquery.com/removeClass/“rel=”removeClass>>>>>>>>>>>>>> 例如:

jQueryObjForCurrentActiveElement.removeClass( active );
jQueryObjForNewElementToMakeActive.addClass( active );

如果你在一次活动中重复这样做,奇怪的是,你想要hasClass

www.un.org/Depts/DGACM/index_spanish.htm 资料来源:。

<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<meta charset=utf-8 />
<title>Test Page</title>
<!--[if IE]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script type= text/javascript >

jQuery(function($) {

  $( div.tabs > ul > li ).click(function(event) {
    var $this = $(this);
    if (!$this.hasClass( active )) {
      display("Activating  " + $this.text() + " ");
      $( div.tabs li.active ).removeClass( active );
      $this.addClass( active );
    }
  });

  function display(msg) {
    $( <p>  + msg +  </p> ).appendTo(document.body);
  }

});​

</script>
<style>
  article, aside, figure, footer, header, hgroup, 
  menu, nav, section { display: block; }
  .active {
    font-weight: bold;
    background-color: #eee;
  }
</style>
</head>
<body>
  <div class= tabs >
    <ul>
      <li class= active ><span>Tab 1</span></li>
      <li><span>Tab 2</span></li>
      <li><span>Tab 3</span></li>
    </ul>
  </div>
</body>
</html>​




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

热门标签