As per below html controls , if I try to change the "id" of Submit to "Save" , click of Save is not working then.

根据下面的html控件,如果我尝试将提交的“id”更改为“保存”,则单击“保存”不起作用。

HTML

<html>
<head>
</head>
<body>
<input type="button" value="Submit Request" id="Submit"class="buttonclass"/>               
<input type="button" id="cancel" value="Cancel" class="buttonclass" />
</body>
</html

JS CODE BELOW :

JS代码如下:

   $("#Submit").on({
    click: function () {             

        $(this).attr('id', 'Save');           
        return false;
    }
   });

   $("#Save").on({
    click: function () {            
       alert("Save Event Fired"); 
    }
   });

1 个解决方案

#1


2

You aren't binding the click event to #Save because the id #Save only exists AFTER the Submit button has been pressed (there is no #Save on load). But if you put the click event on the body and only accept the #Save, you can bubble the event up and handle it there.

您没有将click事件绑定到#Save,因为id #Save仅在按下Submit按钮后才存在(加载时没有#Save)。但是如果你将click事件放在body上并且只接受#Save,你可以将事件冒泡并在那里处理它。

$("#Submit").on('click', function (e) {
    e.stopPropagation()

    alert("Submitted Fired"); 
    $(e.target).attr('id', 'Save');           
    $(this).unbind('click');
})

$("body").on('click', '#Save', function (e) {
    alert("Save Event Fired"); 
})

https://jsfiddle.net/6Lchafwa/1/
If this is the answer you are looking for, press the green tick on the left.

https://jsfiddle.net/6Lchafwa/1/如果这是您正在寻找的答案,请按左侧的绿色勾号。

更多相关文章

  1. bootstrap,模态对话框,shown.bs.modal事件不会触发
  2. 更改html隐藏字段的事件
  3. JQuery 总结(3) jQuery 各种事件
  4. jQuery 选择器 与 事件
  5. jquery不会对select/选项更改事件作出反应。
  6. 绑定和解除相同javascript函数的目的是什么?
  7. 使用HTML5验证时如何绑定到提交事件?
  8. jquery自定义事件
  9. jQuery学习笔记- focus和blur事件妙用

随机推荐

  1. 更改粘性标题航点或偏移的位置。
  2. jquery 如何获取json指定键为指定值的另
  3. 动态生成 ul 的li jquery 点击事件无法获
  4. how to style text after ?
  5. jQuery:在对象内使用.remove()而不是Regex
  6. 使用jQuery在AJAX调用中的url字段格式
  7. Typeahead 0.10.2没有在Rails 4 / Bootst
  8. 告诉javascript首先运行jquery ajax
  9. GET ajax请求发送到同一个php文件
  10. 无法使用jquery发送简单的ajax请求来获取