弹出保存按钮

时间:2018-04-13 09:50:32

标签: jquery

我的目标是更改评论图标。弹出保存按钮时单击。

我的Html:

<input type="text" value="3" name="data_1[]" class="txtfld cell-input">
  <a data-toggle="modal" class="color_comment" href="#myModalMon_1"><i class="fa fa-comment-o"></i></a>
  <div class="modal fade" id="myModalMon_1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-sm">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
          <h4 class="modal-title">Add Comment</h4>
        </div>
        <div class="modal-body">
          <textarea name="data_1[]" rows="7" cols="37">Data of Teaxtarea</textarea>
        </div>
        <div class="modal-footer">
          <button type="button" onclick="save('myModalMon_1')" class="btn btn-round btn-success commentSave">Save</button>
          <button data-dismiss="modal" class="btn btn-round btn-default commentCancel" type="button">Close</button>
        </div>
      </div>
    </div>
  </div>

  <input type="text" value="3" name="data_1[]" class="txtfld cell-input">
  <a data-toggle="modal" class="color_comment" href="#myModalTue_1"><i class="fa fa-comment-o"></i></a>
  <div class="modal fade" id="myModalTue_1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-sm">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
          <h4 class="modal-title">Add Comment</h4>
        </div>
        <div class="modal-body">
          <textarea name="data_1[]" rows="7" cols="37">Data of Teaxtarea</textarea>
        </div>
        <div class="modal-footer">
          <button type="button" onclick="save('myModalTue_1')" class="btn btn-round btn-success commentSave">Save</button>
          <button data-dismiss="modal" class="btn btn-round btn-default commentCancel" type="button">Close</button>
        </div>
      </div>
    </div>
  </div>

我有一组html代码,但是当我点击保存按钮时,它的commant图标就会改变。现在它没有用。

我的jquery:

function save(id){
  $('.color_comment').find('i').removeClass('fa-comment-o').addClass('fa-comments');
}

此jquery代码适用于所有html元素。

1 个答案:

答案 0 :(得分:1)

您必须使用$('#'+ id).prev().find('i').removeClass('fa-comment-o').addClass('fa-comments');

$('#'+ id)引用示例<div class="modal fade" id="myModalMon_1">,然后使用.prev()选择链接,然后使用代码.find('i').removeClass('fa-comment-o').addClass('fa-comments')查找i 并执行某些操作