<input style=" color: red; font-size: 36rpx;font-weight:bold;" disabled="boolean" name='totalPrice' bindchange="totalPriceInputed" value="{{(wxs.getMetalPrices(totalcaltor,ptcaltor,discountcaltor,prices.pt) + wxs.getMetalPrices(totalcaltor,pdcaltor,discountcaltor,prices.pd) + wxs.getMetalPrices(totalcaltor,rhcaltor,discountcaltor,prices.rh) )/10}}"></input> 怎么修改这段代码让value值改变时触发函数totalPriceInputed
时间: 2024-03-26 20:34:05 浏览: 10
可以将代码中的`bindchange`属性修改为`bindinput`,并将`disabled="boolean"`修改为`disabled="{{false}}"`,这样当输入框的值改变时,就会触发`totalPriceInputed`函数。修改后的代码如下:
```
<input style="color: red; font-size: 36rpx; font-weight: bold;" disabled="{{false}}" name='totalPrice' bindinput="totalPriceInputed" value="{{(wxs.getMetalPrices(totalcaltor,ptcaltor,discountcaltor,prices.pt) + wxs.getMetalPrices(totalcaltor,pdcaltor,discountcaltor,prices.pd) + wxs.getMetalPrices(totalcaltor,rhcaltor,discountcaltor,prices.rh) )/10}}"></input>
```
相关问题
<view style="text-align: center;margin-top: 10rpx;"> <view style=" color: red; font-size: 36rpx;font-weight:bold;">总价:</view> <input style=" color: red; font-size: 36rpx;font-weight:bold;" disabled="boolean" name='totalPrice' bindinput="totalPriceInputed" model:value="{{(wxs.getMetalPrices(totalcaltor,ptcaltor,discountcaltor,prices.pt) + wxs.getMetalPrices(totalcaltor,pdcaltor,discountcaltor,prices.pd) + wxs.getMetalPrices(totalcaltor,rhcaltor,discountcaltor,prices.rh) )/10}}"></input> </view>这段代码中bindinput="totalPriceInputed"不能在model:value改变时触发,请问这是为什么?
`bindinput`事件是在用户输入时触发的,而`model:value`是在数据发生变化时才会触发的。所以,当用户在输入框中输入时,`bindinput`事件会被触发,但是当`model:value`发生变化时,`bindinput`事件并不会被触发。
如果想要在`model:value`发生变化时触发事件,应该使用`bindchange`事件。`bindchange`事件会在数据发生变化并且输入框失去焦点时触发。所以,可以将代码中的`bindinput`修改为`bindchange`,这样当`model:value`的值发生变化并且输入框失去焦点时,就会触发`totalPriceInputed`函数。修改后的代码如下:
```
<view style="text-align: center; margin-top: 10rpx;">
<view style="color: red; font-size: 36rpx; font-weight: bold;">总价:</view>
<input style="color: red; font-size: 36rpx; font-weight: bold;" disabled="{{false}}" name="totalPrice" bindchange="totalPriceInputed" model:value="{{(wxs.getMetalPrices(totalcaltor, ptcaltor, discountcaltor, prices.pt) + wxs.getMetalPrices(totalcaltor, pdcaltor, discountcaltor, prices.pd) + wxs.getMetalPrices(totalcaltor, rhcaltor, discountcaltor, prices.rh)) / 10}}"></input>
</view>
```
input::-webkit-input-placeholder { color: red; font-size: 20rpx; }为啥没效果
这是因为 `-webkit-input-placeholder` 属性只适用于 WebKit 内核的浏览器,如 Chrome、Safari 等。如果你想让该样式适用于所有浏览器,可以使用 `::placeholder` 伪类选择器,例如:
```
::placeholder {
color: red;
font-size: 20rpx;
}
```
或者使用所有浏览器都支持的 `:placeholder-shown` 伪类选择器,例如:
```
input:placeholder-shown {
color: red;
font-size: 20rpx;
}
```
另外,`font-size` 属性的单位应该使用 `rem` 或 `em`,而不是 `rpx`,因为 `rpx` 只适用于小程序开发。