2015-11-02 35 views
0
<html> 
<head> 
    <title>List Manipulation</title> 

     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 
    <script> 
     $(document).ready(function(){ 
      $("ul li").click(function(){ 
       var s;// in this variable i want "list item 1" 
       window.alert(s); 
      }); 
     }); 
    </script> 
</head> 
<body> 
    <ul> 
    <li>list item 1</li> 
    </ul> 
</body> 
</html> 

我已經寫了一個簡單的html代碼,它有無序列表。當我點擊這個列表中的元素時,我想要點擊列表元素的內容。我在代碼中評論過它。 我試圖
使用jQuery獲取列表數據

var s = this.text;//giving undefined value 

var s = this.value ;// giving 0 
+2

變種S = $(本)的.text() –

回答

0

使用text()

var s = $(this).text();