【发布时间】:2021-03-29 14:23:17
【问题描述】:
我想在点击按钮数量后设置闪电输入的值,但它不起作用。 并且输入中的 maxlength 也不起作用。它应该设置为最大 99,但也可以设置为 9999999999999999999。
html模板:
<div>
<lightning-button-group key={product.Id}>
<lightning-button
name={product.Id}
value={product.Id}
class="button"
label="-"
onclick={handleQuantityDown}>
</lightning-button>
<lightning-input
type="number"
name={product.Id}
value={textValue}
placeholder="1"
minlength="1"
maxlength="99"
onchange={handleChangeInput}>
</lightning-input>
<lightning-button
name={product.Id}
value={product.Id}
class="button"
label="+"
onclick={handleQuantityUp}>
</lightning-button>
</lightning-button-group>
</div>
<div>
<lightning-button-group key={product.Id}>
<lightning-button
name={product.Id}
value={product.Id}
class="button"
label="-"
onclick={handleQuantityDown}>
</lightning-button>
<lightning-input
type="number"
name={product.Id}
value={textValue}
placeholder="1"
minlength="1"
maxlength="99"
onchange={handleChangeInput}>
</lightning-input>
<lightning-button
name={product.Id}
value={product.Id}
class="button"
label="+"
onclick={handleQuantityUp}>
</lightning-button>
</lightning-button-group>
</div>
js:
import { LightningElement } from 'lwc';
export default class Display extends LightningElement {
clickedButtonQuantityPlus;
handleQuantityUp(event) {
this.clickedButtonQuantityPlus = event.target.name; // get name/ProductID from the button
let input = this.template.querySelector('lightning-input[name=' + this.clickedButtonQuantityPlus + ']'); // set input with ProductID from button
input.value = input.value + 1; // set input value
}
}
如何编辑?
【问题讨论】:
标签: javascript salesforce lwc