【问题标题】:Change dynamic button text on mouseover by jQuery [duplicate]通过jQuery更改鼠标悬停时的动态按钮文本[重复]
【发布时间】:2018-06-04 00:40:50
【问题描述】:

如何通过 jQuery 更改鼠标悬停时的动态按钮文本,

按钮

 <button type="button" id="sendRequest" ><span>Avialable Now</span></button>

jquery

$(document).ready(function(){
    $('#sendRequest').hover(function() {
         $(this).find('span').text('Send Request');
    }, function() {
        $(this).find('span').text('Avialable Now');
 });
});

我想更改每个动态创建的按钮上的文本,上面我只能更改单个或第一个按钮上的文本。

【问题讨论】:

  • 给每个动态创建的按钮一个类名。并使用该类名来更改文本

标签: javascript jquery hover


【解决方案1】:

将您的选择器从 $('#sendRequest') 更改为 $('button')。这将在当前button 上提高event

$(document).ready(function(){
    $('button').hover(function() {
         $(this).find('span').text('Send Request');
    }, function() {
        $(this).find('span').text('Avialable Now');
 });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button type="button" id="sendRequest1" ><span>Avialable Now</span></button>
<button type="button" id="sendRequest2" ><span>Avialable Now</span></button>

【讨论】:

  • @manjunath,不客气。
猜你喜欢
  • 2014-01-30
  • 1970-01-01
  • 2019-02-05
  • 1970-01-01
  • 1970-01-01
  • 2017-07-28
  • 2019-03-07
  • 2012-08-21
  • 2012-08-16
相关资源
最近更新 更多