如何使用jquery或任何其他技术从id属性替换逗号 [英] how to replace comma from id attribute using jquery or any other technologies

查看:80
本文介绍了如何使用jquery或任何其他技术从id属性替换逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



如何从输入标签中删除id属性中的逗号'



< pre lang =xml> < input type = radio < span class =code-attribute> name = name @ {@i} id = roomtype @ {@ id} 已检查 = 已选中 value = @ id / >
< label for = roomtype @ {@ id} class = all_label选中 id = l_1 _ @ {@id} >
& nbsp; < / label >





@id是动态生成的

例如= l_1_1,2,3,4



i想要替换这个l_1_1 ,2,3,4到l_1_1_2_3_4



此输入标记位于forloop内,因此下一个ID将为l_1_4,6,7,8



请给我一个解决方案。

有没有办法在jquery中过滤它



逗号是不是一个有效的东西..但我要做什么我现在被阻止。 ...请给我一个结果来取代逗号..





很好的答案将不胜感激。

解决方案

请参阅: http://msdn.microsoft.com/en-us/library/system.string.replace%28v=vs.110%29.aspx [ ^ ]。



问题是:为什么?



-SA


  var  strTemp =   l_1_1,2,3,4; 
strTemp = strTemp.replace(/,/ g, _);
alert(strTemp);



Enjoy;)


 var a = < span class =code-comment>'  l_1_1,2,3,4' 
a = a.replace(/,/ g, ' _')
alert(a)







这将解决您的问题......


Hi friends ,

How to remove comma from id attribute from input tag'

<input type="radio" name="name@{ @i}" id="roomtype@{@id}" checked="Checked" value="@id" />
                                        <label for="roomtype@{@id}" class="all_label checked" id="l_1_@{ @id}">
                                            &nbsp;</label>



@id is dynamically generated
for example = l_1_1,2,3,4

i want to replace this l_1_1,2,3,4 to l_1_1_2_3_4

this input tag is inside forloop so the next id will be l_1_4,6,7,8

please give me a solution.
is there any way to filter it in jquery

comma is not a valid thing .. but what to do i am blocked now. ... please give me a result to replace comma..


Good answer will be appreciated.

解决方案

Please see: http://msdn.microsoft.com/en-us/library/system.string.replace%28v=vs.110%29.aspx[^].

The question is: why?

—SA


var strTemp = "l_1_1,2,3,4 ";
strTemp = strTemp.replace(/,/g, "_");
alert(strTemp);


Enjoy ;)


var a ='l_1_1,2,3,4'
a=a.replace(/,/g,'_')
alert(a)




This will solve your problem...


这篇关于如何使用jquery或任何其他技术从id属性替换逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆