[英]jQuery change input text value not working
I am trying to do this 我正在尝试这样做
$('input').val($('input').val()+"^2");
so each input field in the page (I have only one field) will have two extra letters ^2 因此页面中的每个输入字段(我只有一个字段)将有两个额外的字母^ 2
the strange thing is that it only append 2 and ignore the ^ symbol. 奇怪的是,它仅附加2而忽略^符号。 any idea why this strange behavior occurs? 知道为什么会发生这种奇怪的行为吗?
EDIT: The problem was that there were another part in the code removes all symbols from the input field once they are inserted. 编辑:问题在于,代码中还有另一部分一旦插入,就会从输入字段中删除所有符号。 So I changed it to ignore this symbol. 因此我将其更改为忽略此符号。 Thanks guys. 多谢你们。
适用于我: jsFiddle示例 。
Try 尝试
^
or escape the carrot: 或逃脱胡萝卜:
/^
It renders as ^ 呈现为^
Try escaping that using a backslash \\ 尝试使用反斜杠转义\\
$('input').val($('input').val()+"\^2");
Or use the Unicode equivalent of the caret 或使用插入符号的Unicode等效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.