简体   繁体   English

从 php 回显时 Javascript 未运行

[英]Javascript not running when echo from php

I am trying to print some code from PHP after clicking button in JavaScript, however the code is not running and I can't see any errors.单击 JavaScript 中的按钮后,我试图从 PHP 打印一些代码,但是代码没有运行,我看不到任何错误。

<script type="text/javascript  src="https://code.jquery.com/jquery- 
3.4.1.min.js" > 
$( document ).ready(function() {
<?php echo '$("button[data-id='. $transport[0]['request']['vehicleType'] 
. ']" ).click();'; ?>
});
</script>

...

<script type="text/JavaScript  src=" https:="" code.jquery.com="" jquery 
3.4.1.min.js"=""> 
$( document ).ready(function() {
$("button[data-id=seated]" ).click();});
</script>

Running the code in console works just fine and the button is clicked,however echoing from php the code is present without errors but not executed and the button is not clicked.在控制台中运行代码工作正常并且按钮被点击,但是从 php 回显代码存在没有错误但没有执行并且没有点击按钮。

the code is not working even like this即使这样,代码也无法正常工作

php php

<script src="https://code.jquery.com/jquery-3.4.1.min.js" >  </script>
<script type="text/javascript"> 
 $( document ).ready(function() {
  <?php echo '$("button[data-id='. $transport[0]['request']['vehicleType'] . ']" ).click();'; ?>
});
 </script>

js output js输出

<script src="https://code.jquery.com/jquery-3.4.1.min.js">  </script>
<script type="text/javascript"> 
 $( document ).ready(function() {
  $("button[data-id=seated]" ).click();});
 </script>

those missing quotes and slashes came from formatting my question, im new to the forum so i wasn't sure how to format the code.那些缺少的引号和斜杠来自格式化我的问题,我是论坛的新手,所以我不确定如何格式化代码。

<script src="https://code.jquery.com/jquery-3.4.1.min.js" >  </script>
<script type="text/javascript"> 

 $( document ).ready(function() {
   setTimeout(function(){ <?php echo '$("button[data-id='. $transport[0]['request']['vehicleType'] . ']" )[0].click()' ?> }, 100)
  setTimeout(function(){  <?php echo '$("input[value='.  $transport[0]['request']['vehicleSpecification'] . ']")[0].click();'; ?> }, 100)
});
 </script>

A small time out and ref to element 0 was enough to make it work短暂的超时和对元素 0 的引用足以使其工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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