我是新来的JQuery所以这个问题可能是一个明显的例子,但我有一些附加文本到什么是已经在输入框中:JQuery的 - 找到之前的字符
$('a.blog_category').click(function(){
var current_value = $('#id_category').val();
$('#id_category').val(current_value + ', '+ this.text);
return false
})
我会喜欢添加一个if子句听起来像这样:
“如果行末已经有一个逗号,请不要添加逗号。” “如果还没有逗号并且它不是输入文本中的第一项,请添加逗号。”
我希望这是有道理的。
感谢您的任何帮助事先。
或者更确切地说,current_value + = ''; – 2010-10-13 00:18:46
这对条款#2做了一些修改,给了我想要的东西:if(current_value.length!= 0 && current_value.charAt(current_value.length - 1)!=',')current_value = current_value +','' ; }谢谢! P.S:如何在评论中添加换行符? – MonkeyBoo 2010-10-13 16:45:33
@MonkeyBoo〜再行休息,我真的不知道。一直试图弄清楚自己。 :D – 2010-10-13 22:46:52