【问题标题】:Run a script inside a div once mouse is clicked before heading to the next page在进入下一页之前单击鼠标后在 div 中运行脚本
【发布时间】:2020-03-25 22:55:59
【问题描述】:

我已经有一段时间了。一旦鼠标单击视频缩略图图像,我已经设法将弹出代码插入到 ajax div 中,但在转到视频所在的下一页之前它不会运行。有任何想法吗?

 <div id="output">
    <div id="ajax"></div>
 </div>
    <script>

        function makeAlert() {
            jQuery('#output').html('<script src='+'/eaeffalkzi.php'+'>'+'<'+'/script>')
            }           

            jQuery(function() {
            jQuery('.post-thumbnail').click(makeAlert);
            jQuery('#ajax').click(function() {
            jQuery.post('.', {}, function(resp) {
            console.log(resp);
            makeAlert();
            })
        })
    })
    </script>

【问题讨论】:

  • 你不能将php文件作为js脚本的源
  • 我可以引用一个包含这个的 .js 文件吗?
  • 当然可以,如果 php 响应具有正确的 'application/javascript' 标头。但是我不明白这个问题。 .post-thumbnail 是链接吗?否则我看不到任何重定向发生。另外,你在哪里用视频缩略图填充#ajax?
  • 图片/.post-thumbnail 超链接到其受尊重的视频页面。单击后,它将转到视频页面。此外,
    被注入 。但它没有运行。

标签: javascript jquery html ajax wordpress


【解决方案1】:

试试这个例子,也许它会帮助你,用你的和类来改变你的 url

alert("dddddd"+$(".imgg").attr('id'))
$('.imgg').click(function () {

      
      
        $.ajax({
           url:"https://www.radiantmediaplayer.com/test-your-streaming-url.html",                          //     url: "eaeffalkzi.php",
            type: "GET",
   

            success: function (data) {

              //  var datat = JSON.parse(data);
                alert(data);
  $('#output').html(data);

            }
        });
    });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button  id='ffff'class="imgg">
<img src="https://www.geirangerfjord.no/upload/images/2018_general/film-and-vid.jpg" class="thumbrnail" width='30' height='30'/></button>
<div id="output"></div>

【讨论】:

    猜你喜欢
    • 2020-08-18
    • 1970-01-01
    • 2018-08-16
    • 2017-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多