我需要返回点击文字

时间:2017-06-24 15:55:53

标签: jquery

我需要返回我所做的所有点击的文本,之后我将在数据层中发送一些,但不能这样做。请帮忙

$("*").click(

    function () {
        {
            var s_name = jQuery(this).find("*").html();
            return s_name;
        }
    }
)

2 个答案:

答案 0 :(得分:1)

这是你想要的吗? $(this).text()这将返回元素的文本。

$("button").click(function () {
  {
    var s_name = $(this).text();
    console.log(s_name);
  }
}
)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button>HELLO</button>
<button>WELCOME</button>

答案 1 :(得分:0)

您可以使用&#34; *&#34;选择器是&#34;所有选择器&#34;。

$("*").click(function(){
  alert($(this).text());
});

这是一个例子

&#13;
&#13;
$("*").click(function(){

alert($(this).text());

});
&#13;
div{
width:50px;
height:50px;
background:pink;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div>Hello</div>
<button>Click me</button>
&#13;
&#13;
&#13;