0

phpのid値をmoodleのjqueryに渡す方法がわかりません。index.php と myscript.js の 2 つのファイルがあります。

index.php ファイル:

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

myscript.js ファイル:

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

});

js ファイルの「data-url」の値を表示する必要があります

pd: html_writer は、html コードを書き込むためのムードル関数です。この場合はボタン タグです。

4

1 に答える 1

2

ボタンの id は であるためbuttonCompile、id のアイテムを見つけることはできませんbuttonbuttonCompile次のコードを使用して、jQuery で属性のデータ URL を取得できます。

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

CFR。data-id 属性を取得するには?

ただし、ボタンのIDを取得したい場合(ページにはボタンが1つしかありません。次のようにすることができます:

$(document).ready(function(){ 
     alert($('button').attr('id')); 
});
于 2013-11-05T16:06:31.997 に答える