GVKun编程网logo

在javascript / PHP

3

在这里,我们将给大家分享关于在javascript/PHP的知识,同时也会涉及到如何更有效地为什么console.log(typeof4+5)在javaScript中返回number5?、为什么pre

在这里,我们将给大家分享关于在javascript / PHP的知识,同时也会涉及到如何更有效地为什么console.log(typeof 4+5) 在javaScript 中返回number5?、为什么preventdefault/stopPropagation 在javascript 中不起作用?、在javascript、在javascript + php laravel中检查父项时自动检查子项的内容。

本文目录一览:

在javascript / PHP

在javascript / PHP

如何解决在javascript / PHP

社区社区,

我正在寻找任何可能的方法来检测我的.jpg文件是否为Camera Raw JPEG。

我现在做什么:

  • 在http://fotoforensics.com或https://www.metadata2go.com上测试了我的“特定”图像,发现有 文件类型JPEG, 文件扩展名为jpg, MIME类型:image / jpeg

  • 还在javascript上检查了文件的前三个字节。有“ FF D8 FF”,所以这是jpeg文件。

  • 还在后端站点上使用imagemagick进行了检查,并且所有数据看起来都与jpeg相同。 Adobe Photoshop将该图像检测为Camera Raw-JPEG,并在“文件信息”设置中显示图像/ tiff格式。

  • 发现,测试的4个jpeg之间只有一个区别是:此特定图像中的图像元数据的Exif图像宽度和Exif图像高度与Image宽度和图像高度不同。其他3个文件具有相同的值。

我的问题是:

是否可以通过javascript / PHP检测Camera Raw JPEG与普通JPEG之间的差异?

感谢您的帮助,

致谢

为什么console.log(typeof 4+5) 在javaScript 中返回number5?

为什么console.log(typeof 4+5) 在javaScript 中返回number5?

如何解决为什么console.log(typeof 4+5) 在javaScript 中返回number5?

为什么这段代码在js中返回number5?我想不通。 console.log(typeof 4+5)

解决方法

MDN 的官方文档中,明确指出:

typeof 运算符返回一个字符串,指示未计算的操作数的类型。

因此,您正在计算的内容类似于 String+Number,它在每种情况下都会导致 String Concatenation。请记住,当有两个操作数的加法运算并且其中一个是 String 时,它总是以字符串连接结束。

为什么preventdefault/stopPropagation 在javascript 中不起作用?

为什么preventdefault/stopPropagation 在javascript 中不起作用?

如何解决为什么preventdefault/stopPropagation 在javascript 中不起作用?

我有一个演示应用程序,其中 preventdefault/stopPropagation 。不确定我哪里做错了。使用 Jquery 它工作正常。按照以下步骤重现错误

  1. 运行应用程序并点击 button

当我输入 jQuery 代码时,它运行良好。它只在控制台上显示 ''jquery:: 1'' 不显示

''jquery:: 2'' 符合预期,因为我们使用了 e.preventDefault();e.stopPropagation();

  1. jQuery(document).on(''click'',''.bclink[href*="bcid="]'',function(e){
  2. e.preventDefault();
  3. e.stopPropagation();
  4. console.log(''jquery:: 1'')
  5. })
  6. jQuery(document).on(''click'',''.clickvideo'',function(e){
  7. // detect .clickvideo-overlay parent to prevent spawning of additional w10 lightBoxes
  8. console.log(''jquery:: 2'')
  9. });

但是当我在 javascript 中使用相同的代码并单击 button 它同时控制 JS:::1JS:::2。为什么阻止默认不起作用

  1. document.addEventListener(''click'',function(e) {
  2. // loop parent nodes from the target to the delegation node
  3. function handler(e){
  4. e.preventDefault();
  5. e.stopPropagation();
  6. console.log("JS:::1")
  7. }
  8. for (var target = e.target; target && target != this; target = target.parentNode) {
  9. if (target.matches(''.bclink[href*="bcid="]'')) {
  10. handler.call(target,e);
  11. break;
  12. }
  13. }
  14. },false)
  15. document.addEventListener(''click'',function(e) {
  16. // loop parent nodes from the target to the delegation node
  17. function handler(e){
  18. e.preventDefault();
  19. e.stopPropagation();
  20. console.log("JS::: 2")
  21. }
  22. for (var target = e.target; target && target != this; target = target.parentNode) {
  23. if (target.matches(''.clickvideo'')) {
  24. handler.call(target,false)
  25. })

这是我的代码 https://jsbin.com/riwazorine/edit?html,output

预期输出:它只显示 "JS:::1",因为我使用了 preventdefault 和 stopPropagation()

解决方法

在 JS 中,两个事件侦听器都附加到同一个元素 - 文档。 stopPropagation 仅停止将事件传播到 其他 元素(祖先或后代),而不是 相同 元素。

您需要 stopImmediatePropagation,它会停止运行同一元素上的其他事件处理程序。

  1. document.addEventListener(''click'',function(e) {
  2. // loop parent nodes from the target to the delegation node
  3. function handler(e) {
  4. e.preventDefault();
  5. e.stopPropagation();
  6. e.stopImmediatePropagation();
  7. console.log("JS:::1")
  8. }
  9. for (var target = e.target; target && target != this; target = target.parentNode) {
  10. if (target.matches(''.bclink[href*="bcid="]'')) {
  11. handler.call(target,e);
  12. break;
  13. }
  14. }
  15. },false)
  16. document.addEventListener(''click'',function(e) {
  17. // loop parent nodes from the target to the delegation node
  18. function handler(e) {
  19. e.preventDefault();
  20. e.stopPropagation();
  21. console.log("JS::: 2")
  22. }
  23. for (var target = e.target; target && target != this; target = target.parentNode) {
  24. if (target.matches(''.clickvideo'')) {
  25. handler.call(target,false)
  1. .bcthumbnail {
  2. width: 100px;
  3. height: 100px;
  4. border: 1px solid
  5. }
  1. <div class="bcthumbnail clickvideo bcimgadded" data-bcid="6086922094001"><a href="?bcid=6086922094001" class="bclink" title="Autonomous Infrastructure: Larry Ellison at Oracle OpenWorld 2019"><button class="vjs-big-play-button"></button>button</a></div>

此外,您可以使用 for 而不是您的 .closest 厕所,它更干净。

  1. document.addEventListener(''click'',(e) => {
  2. if (e.target.closest(''.bclink[href*="bcid="]'')) {
  3. e.preventDefault();
  4. e.stopPropagation();
  5. e.stopImmediatePropagation();
  6. console.log("JS:::1")
  7. }
  8. })
  9. document.addEventListener(''click'',function(e) {
  10. if (e.target.closest(''.clickvideo'')) {
  11. console.log("JS::: 2")
  12. }
  13. })
  1. .bcthumbnail {
  2. width: 100px;
  3. height: 100px;
  4. border: 1px solid
  5. }
  1. <div class="bcthumbnail clickvideo bcimgadded" data-bcid="6086922094001"><a href="?bcid=6086922094001" class="bclink" title="Autonomous Infrastructure: Larry Ellison at Oracle OpenWorld 2019"><button class="vjs-big-play-button"></button>button</a></div>

在javascript

在javascript

如何解决在javascript

我在 firestore 中有一些项目。我想按顺序显示它们,但以随机序列显示。所以,我做了以下代码。在这里我想显示一个特定的问题,然后当单击“下一步”按钮时我想显示下一个项目。在这里,在 forEach 循环中,我将项目渲染到 renderQuestion 函数。他们使用 HTML 和 CSS 在前端展示它们。

但我正在获取这个问题,他们一直显示所有内容直到循环结束。他们不会等待“下一步”按钮被按下。那么,我该如何解决这个问题?我是 JS 新手,如果我已经做错了什么,请原谅我。

  1. renderQuestion = (qID,roomID) => {
  2. q.innerHTML = qID.data().question;
  3. ans1.innerHTML = qID.data().a;
  4. ans2.innerHTML = qID.data().b;
  5. ans3.innerHTML = qID.data().c;
  6. ans4.innerHTML = qID.data().d;
  7. /* next.addEventListener("click",(e) => { //not working
  8. e.preventDefault();
  9. console.log("done");
  10. }); */
  11. };
  12. runningExam = async (review) => {
  13. const totalQ = review.data().total_questions;
  14. let arr = [];
  15. for (let i = 0; i <= totalQ; i++) {
  16. arr.push(false);
  17. }
  18. let n = totalQ;
  19. while (n) {
  20. let randomNumber = getRandom(totalQ);
  21. if (!arr[randomNumber]) {
  22. arr[randomNumber] = true;
  23. await db
  24. .collection("examrooms")
  25. .doc(review.id)
  26. .collection("questions")
  27. .where("serial","==",randomNumber)
  28. .get()
  29. .then((snapshot) => {
  30. snapshot.docs.forEach((doc) => {
  31. renderQuestion(doc,review);
  32. });
  33. });
  34. n--;
  35. }
  36. }
  37. };

解决方法

您似乎试图阻止 runningExam 函数,直到用户按下按钮。我找到了另一个 thread 来实现这一目标。

基本上,将 renderQuestion 函数变成异步函数,并在每次调用时等待用户输入。

  1. renderQuestion = async (qID,roomID) => {
  2. const timeout = async ms => new Promise(res => setTimeout(res,ms));
  3. let userClicked = false;
  4. q.innerHTML = qID.data().question;
  5. ans1.innerHTML = qID.data().a;
  6. ans2.innerHTML = qID.data().b;
  7. ans3.innerHTML = qID.data().c;
  8. ans4.innerHTML = qID.data().d;
  9. next.addEventListener("click",(e) => {
  10. userClicked = true;
  11. e.preventDefault();
  12. console.log("done");
  13. });
  14. while (userClicked === false) await timeout(50);
  15. };

并在runningExam中:

  1. then( async (snapshot) => {
  2. for(let doc of snapshot.docs) {
  3. await renderQuestion(doc,review);
  4. };
  5. });

可能有更好的方法来编写此任务,这只是按照您尝试的方式完成它的一种可能方法。

在javascript + php laravel中检查父项时自动检查子项

在javascript + php laravel中检查父项时自动检查子项

如何解决在javascript + php laravel中检查父项时自动检查子项

我遇到了一个问题,当父母被勾选时,孩子会被自动检查。 图像

enter image description here

我的代码

  1. <tbody id="catRecord">
  2. @PHP $catCode = ""; @endPHP
  3. @if(!empty($data))
  4. @foreach($data as $i=>$cat)
  5. @if($cat->cc_category_code != $catCode )
  6. @if(isset($cat->irel__ref_category))
  7. <tr class="c_row">
  8. <td style=''width: 300px;''>
  9. @for($j=0; $j<$cat->irel__ref_category->Ct_Level; $j++)
  10. &nbsp;&nbsp;&nbsp;&nbsp;
  11. @endfor
  12. <a href="#" class="crudlink"> - {{ $cat->irel__ref_category->Ct_Abbreviation }}</a> // parent data
  13. </td>
  14. <td style=''width: 600px;''>{{ $cat->irel__ref_category->Ct_Description }}</td> //child data
  15. <td style=''width: 20px;''><input type="checkBox" class="ss" name="ss[]" id="ss[]" value="{{ $cat->irel__ref_category->Ct_Code }}^{{ $cat->irel__ref_category->Ct_Abbreviation }}^{{ $cat->irel__ref_category->Ct_Description }}" />
  16. </td>
  17. <input type="hidden" id="cat[]" name="cat[]" value="{{ $cat->irel__ref_category->Ct_Code }}" />
  18. </tr>
  19. @endif
  20. @endif
  21. @PHP $catCode = $cat->cc_category_code; @endPHP
  22. @endforeach
  23. @endif
  24. </tbody>

我找不到方法,因为数据是使用 PHP 在表中获取的,我参考了其他帖子,但似乎仍然找不到方法,我希望有人能提供一些想法。对不起,如果我的解释不清楚

今天关于在javascript / PHP的讲解已经结束,谢谢您的阅读,如果想了解更多关于为什么console.log(typeof 4+5) 在javaScript 中返回number5?、为什么preventdefault/stopPropagation 在javascript 中不起作用?、在javascript、在javascript + php laravel中检查父项时自动检查子项的相关知识,请在本站搜索。

本文标签:

上一篇邀请收件人调查Monkey Collector API PHP(查收邀请函)

下一篇php artisan make:controller PostsController --resource:--resource无法生成函数(php无法加载控制器)