我需要从名为“price”的id中的值中获取数字(条带逗号和货币符号)。我有以下内容:
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>branding</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="manifest" href="site.webmanifest">
<link rel="apple-touch-icon" href="icon.png">
<!-- Place favicon.ico in the root directory -->
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous" type="text/css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css">
<link rel="stylesheet" type="text/css" href="https://rawgit.com/alvarotrigo/fullPage.js/master/jquery.fullPage.css" />
</head>
<body>
<div class="container">
<div id="homepage" class="main">
<div id="fullpage">
<section class="slider section" style="background: url('http://neonrobot.com/wp-content/uploads/2014/09/unsplash-1.jpg') center center;">
<div class="hero">
<div class="header">
<div class="logo"><img src="assets/img/logo.png" alt="logo"></div>
<i id="menu-open" class="fa fa-bars fa-lg"></i>
</div>
<div class="welcome">
<div>
<div class="hero- headings">Hello.</div>
<div class="hero-description"></div>
</div>
</div>
</div>
<div class="clients">
<div class="padding25">
<div class="clients-intro">Our Clients. <i class="fa fa-angle-right"></i><i class="fa fa-angle-right"></i></div>
<div class="clients-logos">sds</div>
</div>
</div>
</section>
</div>
</div>
</div>
<script src="https://www.google-analytics.com/analytics.js" async defer></script>
</body>
</html>
这很好用的价值就像“10.50英镑”。但如果我的值有逗号,例如“£2,050.00”,则返回“050.00”。
我如何获得数字并替换任何货币符号和逗号?
答案 0 :(得分:0)
知道了:
function() {
var element = document.querySelector('*[id^="bew-price"]');
var price = element.innerHTML.replace(/\u00A3/g, '');
var trueprice = price.replace(/,/g , "");
return trueprice;
}