尝试在输入中的文本后面添加字母 [英] Trying to append letter to text inside input
问题描述
我有一个使用禁用属性禁用的文本输入,但是我在单击某些类时向其添加了输入.
I have a text input that is disabled using the disabled attribute, but I add input to it on the click of a certain classes.
在类I(.I)的单击上,我在输入中的现有文本(如果有)上添加一个字母I.
On the click of class I (.I), I add a letter I to the existing text, if any, inside the input.
在类O(.O)上单击时,我在输入中的现有文本(如果有)上添加字母O.
On the click of class O (.O), I add a letter O to the existing text, if any, inside the input.
但是,当我单击课程时似乎什么也没发生.
However nothing seems to be happening when I click the classes.
这是我的代码:
$('.I').click(function(){
$('#code').text($('#code').text()+"I");
});
$('.O').click(function(){
$('#code').text($('#code').text()+"O");
});
这是一个JSFiddel来复制问题: http://jsfiddle.net/q3xBY/
Here is a JSFiddel replicating the problem: http://jsfiddle.net/q3xBY/
推荐答案
要获取并设置输入元素的值,应使用.val()
而不是.text()
.
To get and set the value of an input element, you should use .val()
instead of .text()
.
$('.I').click(function(){
$('#code').val($('#code').val()+"I");
});
$('.O').click(function(){
$('#code').val($('#code').val()+"O");
});
这篇关于尝试在输入中的文本后面添加字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!