简体   繁体   English

将jQuery添加到joomla模块

[英]Add jquery to joomla module

Why jquery magic is not working for me? 为什么jQuery Magic对我不起作用?

In my module_name.php i have: 在我的module_name.php中,我有:

$document = JFactory::getDocument();
$document->addScriptDeclaration('
$(document).ready(function(){
    $("table tr:gt(5)").hide();
    $("#show").click(function(){
    $("table tr:gt(5)").show();
    });
   });
');

In my module tamplate default.php i have: 在我的模块tamplate default.php中,我有:

<table>
<tr>
<td style="width: 33px;" align="center"><strong>№</strong></td>
<td style="width: 148px;"><strong>Ник</strong></td>
<td style="width: 107px;"><strong>Рубли</strong></td>
</tr>
<?php

$position = 1;  

foreach ($top as $row) {
    echo '<tr>';
    echo '<td>' . $position . '</td>';
    echo '<td>' . $row['0'] . '</td>';
    echo '<td>' . $row['1'] . '</td>';
    echo '</tr>';
    $position ++;
 }
 ?>
 </table>
 <input id="show" type="button" value="Раскрыть">

This code has shown a table with the result of JDatabaseQuery which contains in variable $top. 这段代码显示了一个带有JDatabaseQuery结果的表,该表包含在变量$ top中。

In source code of my page i see link to library 在页面的源代码中,我看到了到库的链接

<script src="/media/jui/js/jquery.min.js"></script>

and my jquery script 和我的jQuery脚本

<script>
jQuery(window).on('load',  function() {
            new JCaption('img.caption');
        });
$(document).ready(function(){
    $("table tr:gt(5)").hide();
    $("#show").click(function(){
    $("table tr:gt(5)").show();
    });
});

window.setInterval(function(){var r;try{r=window.XMLHttpRequest?new 
XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP")}catch(e){}if(r)
{r.open("GET","/index.php?
option=com_ajax&format=json",true);r.send(null)}},3600000);
</script>

and table 和桌子

<table>
<tbody>
<tr>
<td style="width: 33px;" align="center"><strong>№</strong></td>
<td style="width: 148px;"><strong>Ник</strong></td>
<td style="width: 107px;"><strong>Опыт</strong></td>
</tr>
<tr><td>1</td><td>dist</td><td>8295</td></tr>
<tr><td>2</td><td>biowolf</td><td>6142</td></tr>
<tr><td>3</td><td>arsen2005</td><td>6002</td></tr>
<tr><td>4</td><td>roman</td><td>5992</td></tr>
<tr><td>5</td><td>cyber</td><td>4305</td></tr>
<tr><td>6</td><td>mik</td><td>3935</td></tr>
<tr><td>7</td><td>artyom</td><td>3646</td></tr>
<tr><td>8</td><td>romeo</td><td>3645</td></tr>
<tr><td>9</td><td>miamivice</td><td>2896</td></tr>
<tr><td>10</td><td>kolya</td><td>2686</td></tr>
</table>

But nothing happen. 但是什么也没发生。 Rows in table does not hide. 表中的行不会隐藏。 Where am I wrong? 我哪里错了?

My mystake was in that there should be this syntax 我的误解是应该使用这种语法

$document = JFactory::getDocument();
$document->addScriptDeclaration('
    (function($){
        $(document).ready(function(){
            $("table tr:gt(5)").hide();
                $("#show").click(function(){
            $("table tr:gt(5)").show();
            });
        });
    })(jQuery);
');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM