admin管理员组文章数量:1375519
So I am building a drag and drop form builder and I want to make a particular field on all the inputs readOnly. This can be
- Select Dropdown
- Text input
- Number input
- Date input
Date input
All these inputs will be generated dynamically.
I had a look at How can i add readonly attribute on all input fields using javascript? & How to set readonly property to false on multiple textboxes with same class?
but none make the name input readOnly just by the class name.
I am currently doing it this way:
$("#editClick").on('click', function(){
$('.myNameClass').attr('readonly', false);
});
But need a way to fire it every time a new field appears on the page(i.e. check is the length of a class increases)
Something like:
if ($(".myNameClass")[0]).increases -> fire event-> and every time it does
So I am building a drag and drop form builder and I want to make a particular field on all the inputs readOnly. This can be
- Select Dropdown
- Text input
- Number input
- Date input
Date input
All these inputs will be generated dynamically.
I had a look at How can i add readonly attribute on all input fields using javascript? & How to set readonly property to false on multiple textboxes with same class?
but none make the name input readOnly just by the class name.
I am currently doing it this way:
$("#editClick").on('click', function(){
$('.myNameClass').attr('readonly', false);
});
But need a way to fire it every time a new field appears on the page(i.e. check is the length of a class increases)
Something like:
if ($(".myNameClass")[0]).increases -> fire event-> and every time it does
Share
Improve this question
edited Jul 18, 2017 at 15:02
Blawless
asked Jul 18, 2017 at 14:43
BlawlessBlawless
1,2993 gold badges17 silver badges29 bronze badges
4
-
1
Your question is missing an important part - what you're actually trying to do...? That said, all you need to do to make an input readonly is call
prop('readonly', true)
on it, but make sure you do it after the element has been appended to the DOM – Rory McCrossan Commented Jul 18, 2017 at 14:44 - 1 Show us at least some HTML + CSS + possible Javascript which you tried, not just just an image. Also be clear about what it does, vs what you want it do do. – Peter B Commented Jul 18, 2017 at 14:46
- Your second link shows exactly what your asking for... what don't you understand? – Heretic Monkey Commented Jul 18, 2017 at 14:52
- updated the info there. – Blawless Commented Jul 18, 2017 at 15:02
1 Answer
Reset to default 6you can do this using this
jQuery <1.9
<script>
$(function () {
$('input[type="text"], textarea').attr('readonly','readonly');
});
</script>
or use this for readonly mode
jQuery 1.9+
$(function () {
$('input[type="text"], textarea').prop("readonly",true);
});
and remove readonly mode
jQuery <1.9
$(function () {
$('input[type="text"], textarea').removeAttr('readonly');
});
</script>
or use this for remove
jQuery 1.9+
$(function () {
$('input[type="text"], textarea').prop("readonly",false);
});
本文标签: javascriptMake all inputs with class readOnlyStack Overflow
版权声明:本文标题:javascript - Make all inputs with class readOnly - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744064142a2584674.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论