douxi3233 2016-01-16 09:05
浏览 50
已采纳

使用Ajax / jQuery将PHP内容输入到CSS Selector中

I'm creating a script that has a needle which points to various degrees and needs to change dynamically. The number of degrees it needs to move is located in degrees.php (In the page is just a number) I am trying to grab the contents of degrees.php and input it into a CSS Selector to move the needle to the right direction.

What I have so far,

Below is my jquery which grabs the content from wind.php which has a number (139) for example and loads it into the DIV ID #windraw. I've then got it setting an interval for it to keep grabbing the content from that page and updating the CSS on the fly as the content changes. Then loading it into that div id tag and.... The part which I'm stuck on, getting the content from #windraw into the CSS Selector "rotate" (https://github.com/jcubic/jquery.rotate)

jQuery:

<script>
    $(document).ready(function() {
    clearInterval(refreshId);
    $("#windraw").load("../raw/wind.php");
     });

    $(document).ready(function() {
    refreshId = setInterval(function() {
    $("#windraw").load("../raw/wind.php");
    $('#winddirneedle').css('rotate', $"#windraw");
    }, 5000);
    });
</script>

I get the error "Uncaught SyntaxError: missing ) after argument list" In my console debug however.

HTML:

<div id="winddircontain"><div id="winddirneedle" style=""></div></div>

winddircontain is a circle and winddirneedle is the needle that points to the right direction.

I'm quite a beginner in jQuery and only know a handful of it. Could someone please point out whats going wrong with my code? Thanks!

  • 写回答

1条回答 默认 最新

  • doufang8282 2016-01-16 09:21
    关注

    It would be better to use $.get for this I think, rather than loading the result into a DOM element first. Also you have some syntax errors.

    $(document).ready(function () {
      var refreshId = setInterval(function () {
        $.get('../raw/wind.php').done(function (result) {
          $('#winddirneedle').css('rotate', result);
        });
      }, 5000);
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何提取csv文件中需要的列,将其整合为一篇完整文档,并进行jieba分词(语言-python)
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?