admin管理员组文章数量:1401829
Onclick I want to change the text to input field. If I change the value in the input field and click anywhere, back to text. I found this fiddle.
/
$('#tbl').on('click','.xx',function() {
$(this).siblings().each(
function(){
if ($(this).find('input').length){
$(this).text($(this).find('input').val());
}
else {
var t = $(this).text();
$(this).text('').append($('<input />',{'value' : t}).val(t));
}
});
});
I used this fiddle. But the input value not changed to text. Please see my updated fiddle.
/
How can to achieve this?
Onclick I want to change the text to input field. If I change the value in the input field and click anywhere, back to text. I found this fiddle.
http://jsfiddle/davidThomas/767y4/8/
$('#tbl').on('click','.xx',function() {
$(this).siblings().each(
function(){
if ($(this).find('input').length){
$(this).text($(this).find('input').val());
}
else {
var t = $(this).text();
$(this).text('').append($('<input />',{'value' : t}).val(t));
}
});
});
I used this fiddle. But the input value not changed to text. Please see my updated fiddle.
http://jsfiddle/5Ach3/
How can to achieve this?
Share Improve this question asked Jun 4, 2014 at 12:01 AkashAkash 2951 gold badge5 silver badges19 bronze badges 2- like this? jsfiddle/5Ach3/1 – Anoop Joshi P Commented Jun 4, 2014 at 12:04
- jsfiddle/modaloda/5Ach3/8 – Mahmoude Elghandour Commented Jun 4, 2014 at 12:11
2 Answers
Reset to default 3Check this Demo Fiddle
$('#tbl').on('click','.xx',function() {
var t = $(this).text();
$(this).text('').append($('<input />',{'value' : t}));
$('input').focus();
});
$('#tbl').on('blur','input',function() {
$(this).parent().text($(this).val());
});
If you just want to transform text to input on click you can use contenteditable="true"
html property.
You don't need any JS with this way.
<p contenteditable="true">my text</p>
http://jsfiddle/9Ec5C/
本文标签: javascriptJquery Onclick text to text fieldStack Overflow
版权声明:本文标题:javascript - Jquery Onclick text to text field - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744319698a2600435.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论