dongya4089 2013-11-05 16:02
浏览 29
已采纳

如何将PHP ID值发送到moodle中的Jquery

I don't know pass a id value of php to jquery in moodle. Have a two files index.php and myscript.js

index.php file:

html_writer::tag('button','', array('id' => 'buttonCompile', 'data-url' => $urlbase));

myscript.js file:

$(document).ready(function(){ 
     alert($('#button').attr('id'));

});

i need show the value of 'data-url' in js file

pd: html_writer is a moodle function for write html code, in this case is a button tag.

  • 写回答

1条回答 默认 最新

  • dongxun3424 2013-11-05 16:06
    关注

    as the id of your button is buttonCompile, you won't be able to find any items with the id button. You can get the data-url of your buttonCompile attribute in jQuery with the following code:

    $(document).ready(function(){ 
         alert($('#buttonCompile').data('url')); 
         //or $('#buttonCompile').attr("data-url")
    });
    

    cfr. How to get the data-id attribute?

    If however you want to get the id of your button (and there is only one button on your page. You could do it like this:

    $(document).ready(function(){ 
         alert($('button').attr('id')); 
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染