如何替换“$$$”使用 Jquery 在字符串中
我使用自动完成方法并溢出标签和值
$("#txt1").autocomplete({
minLength: 1,
source: "/abc/ajax.php?param1=''¶m2="+$("#txt1").attr("value"),
select: function(event, ui)
{
var label= ui.item.label;
var value= ui.item.value;
var Arr = label.split('-');
$('#txt2').val( Arr[1].replace('$$$','') );
}
});
在上面的代码中我从服务器端脚本(PHP)获取名称和值。这里我有三件事要做
1)如何替换“$$$”中的“$$$”带有“”的标签(假设我可能有“($$)”,有时我可能有“($)” 我如何在标签中找到“$”常量并替换为“”(空格)
2)如何减小显示的自动完成值列表的字体大小。
3)我如何将颜色应用于自动完成字段。我以“NAME-Value”这样的方式显示自动完成。 我想为名称和值应用不同的颜色
Iam using auto Complete method and spilliting the label and value
$("#txt1").autocomplete({
minLength: 1,
source: "/abc/ajax.php?param1=''¶m2="+$("#txt1").attr("value"),
select: function(event, ui)
{
var label= ui.item.label;
var value= ui.item.value;
var Arr = label.split('-');
$('#txt2').val( Arr[1].replace('$
In the above code iam getting the name and value from server side script (PHP).Here i have Three thing to do
1)How do I replace the "$$$" in the label with a " " ( Suppose say i may have "($$)" and some time i may have "($)"
how do i find the "$" constant in the label and replace with a " "(space)
2)How do i decrease the Font Size of the list of autocomplete Values that are displayed.
3) How do i apply color to the auto complete field .Iam dispalying the autocomplete in such way "NAME-Value".
I want to apply different color for name and value
,'') );
}
});
In the above code iam getting the name and value from server side script (PHP).Here i have Three thing to do
1)How do I replace the "$$$" in the label with a " " ( Suppose say i may have "($$)" and some time i may have "($)"
how do i find the "$" constant in the label and replace with a " "(space)
2)How do i decrease the Font Size of the list of autocomplete Values that are displayed.
3) How do i apply color to the auto complete field .Iam dispalying the autocomplete in such way "NAME-Value".
I want to apply different color for name and value
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如何替换“$$$”:
我没有使用过 JQuery 的自动完成插件,但 CSS 可能是可行的方法。使用可让您在浏览器中检查 HTML 的工具,以发现要使用的 CSS 选择器。
颜色会相似:
How to replace the "$$$":
I haven't used JQuery's autocomplete plugin, but CSS is probably the way to go. Use a tool that lets you inspect the HTML from in the browers, to discover what CSS selctors to use.
Color would be similar:
您的替换语句应该是正则表达式字符串。
$
表示正则表达式中一行的结尾,要查找美元符号,您需要使用\
转义每个美元符号,因此您的正则表达式应该是\$ 对于您想要匹配的每一个。
其余的,只需使用 CSS
Your replace statement should be a regex string.
$
indicates the end of a line in regex, to find a dollar sign you need to escape each one with a\
so your regex should be\$
for each one you want to match.for the rest, just use CSS