简体   繁体   中英

Google Apps Script HTML Service Key Events

I am using Google Apps Script to create a textbox and validate that the input is numbers only.

$('.numbersOnly').keyup(function () {
    if (!this.value.match(/^([0-9]{0,2})$/)) {
        this.value = this.value.replace(/[^0-9]/g, '').substring(0,2);
    }
});

and

<input type="text" name="height" class="numbersOnly" />

But it doesn't work in my web app. The code works in JSFiddle though.work

You need to include Jquery in your project. Create a pag.html file like these:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 
<div>
<input type="text" name="height" class="numbersOnly" />
<script>
$('.numbersOnly').keyup(function () {
    if (!this.value.match(/^([0-9]{0,2})$/)) {
        this.value = this.value.replace(/[^0-9]/g, '').substring(0,2);
    }
});
</script>
</div>

And create your apps script like this:

function doGet() {
  return HtmlService.createTemplateFromFile("pag.html").evaluate().setSandboxMode(HtmlService.SandboxMode.NATIVE);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM