简体   繁体   English

如何从具有数字的链接中删除下划线,但在具有字母的普通链接上保持下划线

[英]How to remove underline from the link which has number but keep underline on normal link which has alphabets

Please tell me How to remove underline from the link which has number but keep underline on normal link which has alphabets? 请告诉我如何从带有数字的链接中删除下划线,而在具有字母的普通链接上保持下划线?

I created a demo here but not sure how to do this 我在这里创建了一个演示,但不确定如何执行此操作

 a{ text-decoration:underline; } /* TODO - Write code either with CSS or JS for the anchors which has text as number to NOT to have underline */ 
 <a href="#">Login</a> <a href="#">1111</a> <a href="#">2222</a> <a href="#">aavv1111</a> 

CSS does not have the capability to determine if the content of an element is numeric or not, so you will need to use JS. CSS无法确定元素的内容是否为数字,因此您将需要使用JS。

You can attempt to parse the text content of each element to an integer. 您可以尝试将每个元素的文本内容解析为整数。 If it works, remove the underline otherwise, keep it. 如果可行,请删除下划线,否则保留该下划线。 Try this: 尝试这个:

 $('a').css('text-decoration', function(){ return isNaN(parseInt($(this).text(), 10)) ? 'underline' : 'none'; }); 
 a { text-decoration: underline; } 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <a href="#">Login</a> <a href="#">1111</a> <a href="#">2222</a> <a href="#">aavv1111</a> 

You could add another class on the links you don't want to have underlined if your content isn't dynamic or updated. 如果您的内容不是动态或更新的,则可以在不想加下划线的链接上添加其他类。

 a { text-decoration: underline; } a.nounderline { text-decoration: none; } 
 <a href="#">Login</a> <a href="#" class="nounderline">1111</a> <a href="#" class="nounderline">2222</a> <a href="#">aavv1111</a> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM