admin管理员组文章数量:1307448
I have a scenario like this where i have dynamically generated textboxes. I have to validate the textbox for max 15 characters and restricting special characters.
Below is the code by which in document.ready() i am generating the textboxes and binding paste events to them.
$(document).ready(function(){
//Generate textboxes..i have some logic by which i am generating
//textboxes on the fly and giving textboxes a class flagText
GenerateFlagBoxes();
//i am binding the textboxes by class names
var $flagArea = $('.flagText');
$flagArea.bind('paste', function () {
var element = this;
setTimeout(function () {
alert($(element).val());
}, 100);
});
});
But this is not working.The alert i provided is not ing.I think that the controls are created in the ready event can't be bound to listen events.Am i wrong.I don't know why it is happening. I want some suggestions.
Thanks in advance.
This fiddle is working.I am checking , i might be wrong some where.I will update where i am wrong;
/
Yes now working .In the document ready i am able to bind paste event.I was wrong some where in the code. :) Thanks for suggestions.
I have a scenario like this where i have dynamically generated textboxes. I have to validate the textbox for max 15 characters and restricting special characters.
Below is the code by which in document.ready() i am generating the textboxes and binding paste events to them.
$(document).ready(function(){
//Generate textboxes..i have some logic by which i am generating
//textboxes on the fly and giving textboxes a class flagText
GenerateFlagBoxes();
//i am binding the textboxes by class names
var $flagArea = $('.flagText');
$flagArea.bind('paste', function () {
var element = this;
setTimeout(function () {
alert($(element).val());
}, 100);
});
});
But this is not working.The alert i provided is not ing.I think that the controls are created in the ready event can't be bound to listen events.Am i wrong.I don't know why it is happening. I want some suggestions.
Thanks in advance.
This fiddle is working.I am checking , i might be wrong some where.I will update where i am wrong;
http://jsfiddle/mnsscorp/8QFGE/1/
Yes now working .In the document ready i am able to bind paste event.I was wrong some where in the code. :) Thanks for suggestions.
Share Improve this question edited Jul 31, 2018 at 5:21 mns asked Apr 24, 2013 at 17:15 mnsmns 6832 gold badges8 silver badges22 bronze badges 3- 2 $(document).ready(function () { ... }); – Terry Young Commented Apr 24, 2013 at 17:18
- see i have updated..thanks – mns Commented Apr 24, 2013 at 17:19
-
Well, ignoring
GenerateFlagBoxes();
, the rest works fine. Any JavaScript errors? Is your '.flagText' selector actually correct? Or isGenerateFlagBoxes()
generating boxes with incorrect class names? – Terry Young Commented Apr 24, 2013 at 17:20
3 Answers
Reset to default 8Try event delegation for dynamically generated elements -
$(document).on('paste','.flagText',function(){
var element = this;
setTimeout(function () {
alert($(element).val());
}, 100);
});
For dynamic elements, you need an event delegate, such as on
.
Try this:
$("body").on('paste', '.flagText', function () {
setTimeout(function () {
alert($(this).val());
}, 100);
});
use target
var $flagArea = $('.flagText');
$flagArea.bind('paste', function (e) {
setTimeout(function () {
alert(e.target.value);
}, 100);
});
本文标签: javascriptGetting value from a TextBox after pasteStack Overflow
版权声明:本文标题:javascript - Getting value from a TextBox after paste - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741816954a2399134.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论