input在HTML校验正负数特殊字符

swal({
title: '',
html:
'<p style="font-weight:bold;">Please input adjusted amount</p>' +
'<input type="text" style="width:310px;height:35px;" id="adjustedAmountInput" placeholder="+500/-500" onKeyUp="if(isNaN(value)&&!/^-$/.test(value))value=\'\';if(!/^[+-]?\.{0,1}\d{0,1}$/.test(value))value = value.replace(/\.\d{2,}$/,value.substr(value.indexOf(\'.\'),3))">' +
'</br></br><p style="font-weight:bold;">Comment</p>' +
'<textarea id="commentTextArea" type="text" name="fname" style="width:380px;height:125px;resize:none;margin-bottom:-15px;" placeholder="This is the reminder for clicking Edit "/></textarea>' ,
showCancelButton: true,
confirmButtonText: 'SAVE',
cancelButtonText: 'CANCEL',
}).then((isConfirm) => {
try {

 

 


主要需要注意if判断,转义字符

 

'<input type="text" style="width:310px;height:35px;" id="adjustedAmountInput" placeholder="+500/-500" onKeyUp="if(isNaN(value)&&!/^-$/.test(value))value=\'\';if(!/^[+-]?\.{0,1}\d{0,1}$/.test(value))value = value.replace(/\.\d{2,}$/,value.substr(value.indexOf(\'.\'),3))">' +

posted @ 2020-12-10 18:27  我和我的小生活  阅读(445)  评论(0编辑  收藏  举报