<div class="totalPrice totalPrice2"><i>参考价: </i><span class="">395</span><i>万</i></div>如何只取395
时间: 2023-11-02 21:16:39 浏览: 39
您可以使用字符串切片或正则表达式来提取数字部分。以下是字符串切片的示例代码:
```python
price_str = '<div class="totalPrice totalPrice2"><i>参考价: </i><span class="">395</span><i>万</i></div>'
start_index = price_str.index('">') + 2
end_index = price_str.index('</span>')
price = price_str[start_index:end_index]
print(price)
```
输出结果为:
```
395
```
以下是正则表达式的示例代码:
```python
import re
price_str = '<div class="totalPrice totalPrice2"><i>参考价: </i><span class="">395</span><i>万</i></div>'
pattern = re.compile(r'<span.*?>(.*?)</span>')
match = pattern.search(price_str)
if match:
price = match.group(1)
print(price)
```
输出结果为:
```
395
```
相关问题
<p style="font-size: x-large">总价:¥{{ total }}<span id="totalPrice">0</span></p> <div style="width: 50%"> <div class="form-group"> <label for="name">收货人姓名</label> <input type="text" class="form-control" id=name" name="name" value="{{ user.customer.name }}"> </div> <div class="form-group"> <label for="name">电话</label> <input type="tel" class="form-control" id="name" name="phone" value="{{ user.customer.phone }}"> </div> <div class="form-group"> <label for="name">地址</label> <input type="text" class="form-control" id="name" name="address" value="{{ user.customer.address }}"> </div> <div class="form-group"> <label for="name">支付方式</label> <select type="text" class="form-control" id="name" name="method"> <option value="支付宝">支付宝</option> <option value="微信">微信</option> <option value="银行卡">银行卡</option> </select> </div> <div class="form-group"> <button type="submit" class="btn btn-primary">提交</button> </div> </div>
代码中有两个地方的 `id` 属性值都是 "name",这会导致重复的 id 引用。为了解决这个问题,可以将这两个 `id` 属性值修改为不同的值,例如:
```
<p style="font-size: x-large">总价:¥{{ total }}<span id="totalPrice">0</span></p>
<div style="width: 50%">
<div class="form-group">
<label for="name">收货人姓名</label>
<input type="text" class="form-control" id="name" name="name" value="{{ user.customer.name }}">
</div>
<div class="form-group">
<label for="phone">电话</label>
<input type="tel" class="form-control" id="phone" name="phone" value="{{ user.customer.phone }}">
</div>
<div class="form-group">
<label for="address">地址</label>
<input type="text" class="form-control" id="address" name="address" value="{{ user.customer.address }}">
</div>
<div class="form-group">
<label for="method">支付方式</label>
<select type="text" class="form-control" id="method" name="method">
<option value="支付宝">支付宝</option>
<option value="微信">微信</option>
<option value="银行卡">银行卡</option>
</select>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">提交</button>
</div>
</div>
```
这样就可以避免重复的 id 引用了。
<!-- 结算模块 --> <div class="cart-floatbar"> <div class="select-all"> <input type="checkbox" name="" id="d" class="checkall">全选 </div> <div class="operation"> <a href="javascript:;" class="remove-batch"> 删除选中的商品</a> <a href="javascript:;" class="clear-all">清理购物车</a> </div> <div class="toolbar-right"> <div class="amount-sum">已经选<em>1</em>件商品</div> <div class="price-sum">总价: <em> </em></div> <div class="btn-area">去结算</div> </div> </div>帮我改成组件
可以将上述代码封装成一个名为 "CartFloatBar" 的组件,代码如下所示:
```
<template>
<div class="cart-floatbar">
<div class="select-all">
<input type="checkbox" name="" id="d" class="checkall">全选
</div>
<div class="operation">
<a href="javascript:;" class="remove-batch"> 删除选中的商品</a>
<a href="javascript:;" class="clear-all">清理购物车</a>
</div>
<div class="toolbar-right">
<div class="amount-sum">已经选<em>{{ selectedCount }}</em>件商品</div>
<div class="price-sum">总价: <em>{{ totalPrice }}</em></div>
<div class="btn-area">去结算</div>
</div>
</div>
</template>
<script>
export default {
name: 'CartFloatBar',
props: {
selectedCount: {
type: Number,
default: 0
},
totalPrice: {
type: Number,
default: 0
}
}
}
</script>
```
在使用该组件时,可以通过传递不同的 props 来动态显示已选商品数量和总价。例如:
```
<CartFloatBar :selectedCount="1" :totalPrice="99"></CartFloatBar>
```