j.Query.inArray在外部列表上无法正常工作,但在普通数组上可以正常工作。

huangapple go评论87阅读模式
英文:

j.Query.inArray not working with external list but working with normala array

问题

I am working on a website that only allows sign-ups from business email addresses, so I have to check if the entered email is a free email and restrict registration.

My problem is when I manually enter the domains into my array, everything works fine, but when I load the domains from a text file into the array, it doesn't work.

英文:

I am working on a website that only allow sign up from business email so i have to check if the entered email is a free email and restrict registration.

My problem is when i enter the domains manually in my array, everything works fine but when i load the domains from a txt file in to the array, it doesn't work.

Please can anybody help. I have tried everything including reducing the domains in the list but still nothing works

  1. <script type="text/javascript">
  2. $(document).ready(function () {
  3. var blocked = new Array;
  4. $.get("https://cdn.jsdelivr.net/gh/cokeboyyy/blackout@main/blocked.txt", function (data) {
  5. var blocked = data.split("\n");
  6. console.log(blocked);
  7. });
  8. $("button").click(function () {
  9. var domain = $("input").val();
  10. if (jQuery.inArray(domain, blocked) !== -1) {
  11. $("#check").html("available");
  12. } else {
  13. $("#check").html("not available");
  14. }
  15. });
  16. });
  17. </script>

答案1

得分: 0

只需删除get函数中的var

  1. $(document).ready(function() {
  2. var blocked = new Array;
  3. $.get("https://cdn.jsdelivr.net/gh/cokeboyyy/blackout@main/blocked.txt", function(data) {
  4. blocked = data.split("\n");
  5. });
  6. $("button").click(function() {
  7. var domain = $("input").val();
  8. if (jQuery.inArray(domain, blocked) !== -1) {
  9. $("#check").html("available");
  10. } else {
  11. $("#check").html("not available");
  12. }
  13. });
  14. });
  1. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  2. <input type="text" id="input">
  3. <button>check</button>
  4. <div id="check"></div>
英文:

Just delete the var in get function.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

  1. $(document).ready(function() {
  2. var blocked = new Array;
  3. $.get(&quot;https://cdn.jsdelivr.net/gh/cokeboyyy/blackout@main/blocked.txt&quot;, function(data) {
  4. blocked = data.split(&quot;\n&quot;);
  5. });
  6. $(&quot;button&quot;).click(function() {
  7. var domain = $(&quot;input&quot;).val();
  8. if (jQuery.inArray(domain, blocked) !== -1) {
  9. $(&quot;#check&quot;).html(&quot;available&quot;);
  10. } else {
  11. $(&quot;#check&quot;).html(&quot;not available&quot;);
  12. }
  13. });
  14. });

<!-- language: lang-html -->

  1. &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js&quot;&gt;&lt;/script&gt;
  2. &lt;input type=&quot;text&quot; id=&quot;input&quot;&gt;
  3. &lt;button&gt;check&lt;/button&gt;
  4. &lt;div id=&quot;check&quot;&gt;&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年5月15日 08:38:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76250240.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定