簡體   English   中英

如何在Moodle中自定義$ mform-> createElement

[英]How to customize $mform->createElement in moodle

$attr = "onChange = alert('hi');";
$objs = array();
        $objs[] =& $mform->createElement('select', $this->name.'_op', null,  '',$this->get_operators(), $attr);

以上是我的代碼,此處未在我的選擇框中添加javascript。

實際上,穆德爾文件說第4個參數是值,第5個參數是屬性,但是上面的代碼第5個參數是值和屬性在任何地方都不起作用。 如何自定義createElement函數。

他現在離開的另一個開發人員將moodle和php版本從5.6升級到php 7.1,現在出現此問題

賈亞維爾

您以錯誤的數字傳遞了$ attr,第5個參數是每個參數文檔的屬性參數https://docs.moodle.org/dev/lib/formslib.php_Form_Definition#select

從更改您的代碼

 $objs[] =& $mform->createElement('select', $this->name.'_op', null,  '',$this->get_operators(), $attr);

$objs[] =& $mform->createElement('select', $this->name.'_op', null,  '', $attr);

這樣,您將獲得有關選擇框數據更改的javascript警報。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM