2016-08-03 46 views

回答

0

簡單String.replace用正則表達式/[a-z]/ig可以做到!

var str = "avc234jw6"; 
 
var no = parseInt(str.replace(/[a-z]/ig, "")); 
 

 
console.log(no);

0

非編問題回答 「如何從〜應變刪除字符?」

var removeChar = "a"; 
 
var string \t = \t "abc abc abc"; 
 

 
function removeFromString(char, string){ 
 
var newString = ""; 
 
    for (var i = 0; i < string.length; i++) { 
 
     if(string[i].toLowerCase() == char){ 
 
      continue; 
 
     } else { 
 
     newString += string[i]; 
 
     } 
 
    } 
 
    return newString; 
 
} 
 

 
$("#test").html(removeFromString(removeChar, string));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div id="test"> 
 
test 
 
</div>

相關問題