Javascript 应用程序生成器的时间选择器和自动完成

Javascript 应用程序生成器的时间选择器和自动完成,javascript,jquery,google-app-maker,Javascript,Jquery,Google App Maker,寻找一个解决方案来选择时间,而不使用2个下拉菜单和自动完成搜索框 自动完成框示例: 时间选择器示例: 我正在寻找一种方法,既可以使用这两种方法,也可以将值取出来。我遇到了一些问题,无法通过HTML小部件选择元素,JS的非功能似乎也能正常工作 除了复制粘贴代码和一些错误之外,我没有任何东西可以在这里显示 错误1:HTML小部件->自动完成输入onclick找不到函数 错误2:时钟选择器根本不工作。未报告任何错误。可能是因为找不到元素或单击功能未启动。请在Google App Maker中创建一个新

寻找一个解决方案来选择时间,而不使用2个下拉菜单和自动完成搜索框

自动完成框示例:

时间选择器示例:

我正在寻找一种方法,既可以使用这两种方法,也可以将值取出来。我遇到了一些问题,无法通过HTML小部件选择元素,JS的非功能似乎也能正常工作

除了复制粘贴代码和一些错误之外,我没有任何东西可以在这里显示

错误1:HTML小部件->自动完成输入onclick找不到函数


错误2:时钟选择器根本不工作。未报告任何错误。可能是因为找不到元素或单击功能未启动。

请在Google App Maker中创建一个新的空白应用程序,然后请按照下面的分步指南来实现与相同的效果


---自动完成输入---

1) 。创建客户端脚本并粘贴以下代码:

function autocomplete(inp, arr) {
  /*the autocomplete function takes two arguments,
  the text field element and an array of possible autocompleted values:*/
  var currentFocus;
  /*execute a function when someone writes in the text field:*/
  inp.addEventListener("input", function(e) {
    var a, b, i, val = this.value;
    /*close any already open lists of autocompleted values*/
    closeAllLists();
    if (!val) { return false;}
    currentFocus = -1;
    /*create a DIV element that will contain the items (values):*/
    a = document.createElement("DIV");
    a.setAttribute("id", this.id + "autocomplete-list");
    a.setAttribute("class", "autocomplete-items");
    /*append the DIV element as a child of the autocomplete container:*/
    this.parentNode.appendChild(a);
    /*for each item in the array...*/
    for (i = 0; i < arr.length; i++) {
      /*check if the item starts with the same letters as the text field value:*/
      if (arr[i].substr(0, val.length).toUpperCase() == val.toUpperCase()) {
        /*create a DIV element for each matching element:*/
        b = document.createElement("DIV");
        /*make the matching letters bold:*/
        b.innerHTML = "<strong>" + arr[i].substr(0, val.length) + "</strong>";
        b.innerHTML += arr[i].substr(val.length);
        /*insert a input field that will hold the current array item's value:*/
        b.innerHTML += "<input type='hidden' value='" + arr[i] + "'>";
        /*execute a function when someone clicks on the item value (DIV element):*/
        b.addEventListener("click", function(e) {
          /*insert the value for the autocomplete text field:*/
          inp.value = this.getElementsByTagName("input")[0].value;
          /*close the list of autocompleted values,
              (or any other open lists of autocompleted values:*/
          closeAllLists();
        });
        a.appendChild(b);
      }
    }
  });
  /*execute a function presses a key on the keyboard:*/
  inp.addEventListener("keydown", function(e) {
    var x = document.getElementById(this.id + "autocomplete-list");
    if (x) x = x.getElementsByTagName("div");
    if (e.keyCode == 40) {
      /*If the arrow DOWN key is pressed,
        increase the currentFocus variable:*/
      currentFocus++;
      /*and and make the current item more visible:*/
      addActive(x);
    } else if (e.keyCode == 38) { //up
      /*If the arrow UP key is pressed,
        decrease the currentFocus variable:*/
      currentFocus--;
      /*and and make the current item more visible:*/
      addActive(x);
    } else if (e.keyCode == 13) {
      /*If the ENTER key is pressed, prevent the form from being submitted,*/
      e.preventDefault();
      if (currentFocus > -1) {
        /*and simulate a click on the "active" item:*/
        if (x) x[currentFocus].click();
      }
    }
  });
  function addActive(x) {
    /*a function to classify an item as "active":*/
    if (!x) return false;
    /*start by removing the "active" class on all items:*/
    removeActive(x);
    if (currentFocus >= x.length) currentFocus = 0;
    if (currentFocus < 0) currentFocus = (x.length - 1);
    /*add class "autocomplete-active":*/
    x[currentFocus].classList.add("autocomplete-active");
  }
  function removeActive(x) {
    /*a function to remove the "active" class from all autocomplete items:*/
    for (var i = 0; i < x.length; i++) {
      x[i].classList.remove("autocomplete-active");
    }
  }
  function closeAllLists(elmnt) {
    /*close all autocomplete lists in the document,
    except the one passed as an argument:*/
    var x = document.getElementsByClassName("autocomplete-items");
    for (var i = 0; i < x.length; i++) {
      if (elmnt != x[i] && elmnt != inp) {
        x[i].parentNode.removeChild(x[i]);
      }
    }
  }
  /*execute a function when someone clicks in the document:*/
  document.addEventListener("click", function (e) {
    closeAllLists(e.target);
  });
}
4) 。转到样式编辑器并将以下css粘贴到页面样式部分:

.autocomplete-items {
  position: absolute;
  border: 1px solid #d4d4d4;
  border-bottom: none;
  border-top: none;
  z-index: 99;
  /*position the autocomplete items to be the same width as the container:*/
  top: 100%;
  left: 0;
  right: 0;
}
.autocomplete-items div {
  padding: 10px;
  cursor: pointer;
  background-color: #fff; 
  border-bottom: 1px solid #d4d4d4; 
}
.autocomplete-items div:hover {
  /*when hovering an item:*/
  background-color: #e9e9e9; 
}
.autocomplete-active {
  /*when navigating through the items using the arrow keys:*/
  background-color: DodgerBlue !important; 
  color: #ffffff; 
}
5) 。可选:添加占位符值:键入以自动完成


---Jquery时钟选择器---

1) 。确保在应用程序中按正确顺序添加了所需的javascript和css外部资源:(首先是jquery-min.js,然后是jquery-clockpicker.min.js)

在上图中,我正在使用服务器上托管的资源。制作 确保你拥有自己的主机或获得CDN,因为我可能会删除它们。这个 外部资源必须通过HTTPS提供

2) 。在UI中删除另一个TextBox小部件并添加一些宽度

3) 。在此文本框小部件的onAttach事件处理程序上,添加以下内容:

$('.clockpicker').clockpicker({
    donetext: 'Done'
});
4) 。最后,确保将这两个样式类都添加到此TextBox小部件:


5) 。可选:添加占位符值:拾取时间在Google App Maker中创建一个新的空白应用程序,然后请按照下面的分步指南操作,以达到与相同的效果


---自动完成输入---

1) 。创建客户端脚本并粘贴以下代码:

function autocomplete(inp, arr) {
  /*the autocomplete function takes two arguments,
  the text field element and an array of possible autocompleted values:*/
  var currentFocus;
  /*execute a function when someone writes in the text field:*/
  inp.addEventListener("input", function(e) {
    var a, b, i, val = this.value;
    /*close any already open lists of autocompleted values*/
    closeAllLists();
    if (!val) { return false;}
    currentFocus = -1;
    /*create a DIV element that will contain the items (values):*/
    a = document.createElement("DIV");
    a.setAttribute("id", this.id + "autocomplete-list");
    a.setAttribute("class", "autocomplete-items");
    /*append the DIV element as a child of the autocomplete container:*/
    this.parentNode.appendChild(a);
    /*for each item in the array...*/
    for (i = 0; i < arr.length; i++) {
      /*check if the item starts with the same letters as the text field value:*/
      if (arr[i].substr(0, val.length).toUpperCase() == val.toUpperCase()) {
        /*create a DIV element for each matching element:*/
        b = document.createElement("DIV");
        /*make the matching letters bold:*/
        b.innerHTML = "<strong>" + arr[i].substr(0, val.length) + "</strong>";
        b.innerHTML += arr[i].substr(val.length);
        /*insert a input field that will hold the current array item's value:*/
        b.innerHTML += "<input type='hidden' value='" + arr[i] + "'>";
        /*execute a function when someone clicks on the item value (DIV element):*/
        b.addEventListener("click", function(e) {
          /*insert the value for the autocomplete text field:*/
          inp.value = this.getElementsByTagName("input")[0].value;
          /*close the list of autocompleted values,
              (or any other open lists of autocompleted values:*/
          closeAllLists();
        });
        a.appendChild(b);
      }
    }
  });
  /*execute a function presses a key on the keyboard:*/
  inp.addEventListener("keydown", function(e) {
    var x = document.getElementById(this.id + "autocomplete-list");
    if (x) x = x.getElementsByTagName("div");
    if (e.keyCode == 40) {
      /*If the arrow DOWN key is pressed,
        increase the currentFocus variable:*/
      currentFocus++;
      /*and and make the current item more visible:*/
      addActive(x);
    } else if (e.keyCode == 38) { //up
      /*If the arrow UP key is pressed,
        decrease the currentFocus variable:*/
      currentFocus--;
      /*and and make the current item more visible:*/
      addActive(x);
    } else if (e.keyCode == 13) {
      /*If the ENTER key is pressed, prevent the form from being submitted,*/
      e.preventDefault();
      if (currentFocus > -1) {
        /*and simulate a click on the "active" item:*/
        if (x) x[currentFocus].click();
      }
    }
  });
  function addActive(x) {
    /*a function to classify an item as "active":*/
    if (!x) return false;
    /*start by removing the "active" class on all items:*/
    removeActive(x);
    if (currentFocus >= x.length) currentFocus = 0;
    if (currentFocus < 0) currentFocus = (x.length - 1);
    /*add class "autocomplete-active":*/
    x[currentFocus].classList.add("autocomplete-active");
  }
  function removeActive(x) {
    /*a function to remove the "active" class from all autocomplete items:*/
    for (var i = 0; i < x.length; i++) {
      x[i].classList.remove("autocomplete-active");
    }
  }
  function closeAllLists(elmnt) {
    /*close all autocomplete lists in the document,
    except the one passed as an argument:*/
    var x = document.getElementsByClassName("autocomplete-items");
    for (var i = 0; i < x.length; i++) {
      if (elmnt != x[i] && elmnt != inp) {
        x[i].parentNode.removeChild(x[i]);
      }
    }
  }
  /*execute a function when someone clicks in the document:*/
  document.addEventListener("click", function (e) {
    closeAllLists(e.target);
  });
}
4) 。转到样式编辑器并将以下css粘贴到页面样式部分:

.autocomplete-items {
  position: absolute;
  border: 1px solid #d4d4d4;
  border-bottom: none;
  border-top: none;
  z-index: 99;
  /*position the autocomplete items to be the same width as the container:*/
  top: 100%;
  left: 0;
  right: 0;
}
.autocomplete-items div {
  padding: 10px;
  cursor: pointer;
  background-color: #fff; 
  border-bottom: 1px solid #d4d4d4; 
}
.autocomplete-items div:hover {
  /*when hovering an item:*/
  background-color: #e9e9e9; 
}
.autocomplete-active {
  /*when navigating through the items using the arrow keys:*/
  background-color: DodgerBlue !important; 
  color: #ffffff; 
}
5) 。可选:添加占位符值:键入以自动完成


---Jquery时钟选择器---

1) 。确保在应用程序中按正确顺序添加了所需的javascript和css外部资源:(首先是jquery-min.js,然后是jquery-clockpicker.min.js)

在上图中,我正在使用服务器上托管的资源。制作 确保你拥有自己的主机或获得CDN,因为我可能会删除它们。这个 外部资源必须通过HTTPS提供

2) 。在UI中删除另一个TextBox小部件并添加一些宽度

3) 。在此文本框小部件的onAttach事件处理程序上,添加以下内容:

$('.clockpicker').clockpicker({
    donetext: 'Done'
});
4) 。最后,确保将这两个样式类都添加到此TextBox小部件:



5) 。可选:添加占位符值:拾取时间

需要查看一些代码,错误代码在这两个链接中。纯拷贝粘贴。唯一的错误是“找不到函数”,无论我将其设置为什么函数。我正在使用一个空白的网站进行测试,所以没有其他代码。它只是一个html小部件。如果它是纯复制粘贴,那么设置一个简单的js代码段来重新创建错误应该很简单。这是在google app maker中制作的。作为标准,HTML小部件不支持运行JS,允许不安全的HTML被认为可以绕过此限制,但即使这样,它也无法工作。我有它在谷歌应用程序脚本的工作表,但它仍然在应用程序制造商失败,我不知道为什么。我的问题要么是寻找一个可行的替代方案,要么是寻找它失败的原因。没有人会回答你的问题,因为没有人能够回答你的问题。没有代码,没有错误,没有答案。如果您需要在示例中运行JS,则需要查看一些代码,错误代码位于这两个链接中。纯拷贝粘贴。唯一的错误是“找不到函数”,无论我将其设置为什么函数。我正在使用一个空白的网站进行测试,所以没有其他代码。它只是一个html小部件。如果它是纯复制粘贴,那么设置一个简单的js代码段来重新创建错误应该很简单。这是在google app maker中制作的。作为标准,HTML小部件不支持运行JS,允许不安全的HTML被认为可以绕过此限制,但即使这样,它也无法工作。我有它在谷歌应用程序脚本的工作表,但它仍然在应用程序制造商失败,我不知道为什么。我的问题要么是寻找一个可行的替代方案,要么是寻找它失败的原因。没有人会回答你的问题,因为没有人能够回答你的问题。没有代码,没有错误,没有答案。如果您需要在示例中运行JS,请使用“谢谢”。自动完成的代码工作得很好,我很确定我可以修改它来接受数据源,而不是固定数组。不过,时钟选择器似乎不想工作。我获取了Jquery和源代码,但我得到一个错误:$(…)。时钟选择器不是function@ScottPaterson出现该错误的原因是jquery-clockpicker.min.js未正确导入。您确定您使用的是正确的版本并且它是通过https提供的吗?@ScottPaterson还确保jquery库也正确导入。它应该在jquery-clockpicker.App设置->外部资源->的上方,然后在CSS部分,这些是我从JSFIDLE的外部资源部分中提取的链接,它们在页面上可用,谢谢。我设法将它们上传到硬盘,并从那里获得了https链接。谢谢。自动完成的代码工作得很好,而且很好