嗨,专家,这是我的代码,我被困在this
关键字如何向对象添加属性。
function carMaker(){
this.companyName='Lamborghini';
}
let LamborghiniUrus = new carMaker();
carMaker.prototype.country="Italy"
LamborghiniUrus.price="200000";
Run Code Online (Sandbox Code Playgroud)
我知道添加了属性this
并Object.prototype
继承了所有对象,但是两者都是等效的,即this
是否还在原型中添加属性?
如果是,那么为什么console.log(carMaker.prototype.companyName)
未定义。
如果没有,那么我们如何访问this
在同一对象中添加的属性(在我的情况下是carMake功能)。
并且确实 this.companyName='Lamborghini'
和LamborghiniUrus.price="200000"
等价。
我在模糊事件中使用货币管道。但它第一次工作正常,当我收到验证错误消息时,如果我删除了几个数字并出来,它不会被格式化为货币格式仍然是用户删除的格式。例如,我给出了这个数字:
36543265
所以当我从输入中出来时,它被格式化为$36,543,265.00
,带有验证错误消息。所以如果我265.00
从 中删除
$36,543,265.00
,我仍然有错误验证消息。所以验证错误消息消失并保持这种格式,$36,543
但它没有达到正确的格式。USD
清除验证消息后,如何使其成为正确的货币管道格式。
如何根据用户删除的值使其正确格式化。
TS:
public transformAmount(element, name) {
if (name == "amount") {
let formattedAmount = this.currencyPipe.transform(this.eoInfoForm.value.amount, 'USD');
element.target.value = formattedAmount;
this.eoInfoForm.get('amount').setValue(formattedAmount);
if (this.eoInfoForm.get('amount').status === 'VALID') {
this.amt = false;
}
else {
this.amt = true;
}
}
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<input type="text" class="form-control" placeholder="Amount in dolars"
formControlName="amount" autocomplete="off" maxlength="8" allowNumberOnly (blur)="transformAmount($event,'amount')" [ngClass]="{ 'is-invalid': amt && eoInfo.amount.invalid }">
<div *ngIf="amt && eoInfo.amount.invalid" class="invalid-feedback">
<div *ngIf="amt && eoInfo.amount.invalid">Maximum of 8 …
Run Code Online (Sandbox Code Playgroud) 我有一个table
,我正在添加新行javascript
并event
在新行上添加一个,但它不起作用。
这是我的代码:
function moreitem() {
document.getElementById('tottr').value = parseInt(document.getElementById('tottr').value) + 1;
ain = document.getElementById('tottr').value;
$('#mytable tbody tr:last')
.after("<tr><td><select name='pid[]' id='' class='form-control' onchange='getstock(this.value,'st" + ain + "','pc" + ain + "')'><option value=''>Select Product</option><option value='1'>Drink</option></select></td><td><input type='text' id='st" + ain + "' placeholder='Available Stock' class='form-control'></td><td><input type='text' id='qty" + ain + "' onchange='gettot(this.value,ain)' name='qty[]' placeholder='Quantity' class='form-control'></td><td><input type='text' id='pc" + ain + "' name='pprice[]' placeholder='Per Piece Price' class='form-control'></td><td><input type='text' name='tprice[]' placeholder='Total Price' id='tp" + ain + "' class='form-control'></td></tr>");
}
function …
Run Code Online (Sandbox Code Playgroud)