這裏是我的PHP代碼塊,其中我渲染表格行: -爲什麼我不能使用JQuery隱藏和顯示元素?
其實我想要實現的是,在第一行中按鈕的點擊,我應該能夠顯示下一個行,這是以前在文檔就緒腳本中使用.hide()隱藏的。
<?php
echo "<tr>";
echo "<td>"."<button id= \"btnnumber_". $i ." \" class=\"btn info toggler\" data-value=\" $val\">Show Info <i class=\"icon-arrow-down\"></i></button>"."</td>"; // On click of this button I am taking its id in Jquery getting the number at end creating the id of the next row in the Jquery script.
echo "</tr>";
echo "</tr>";
echo "<tr id=\"row_$i \" class=\"info_row\">";// This row is dynamically generated one each row has its unique id like 0 row is having id row_0,1 row is having id row_1 etc.
echo "<td id=\"student_count\">"."students count:"."</td>";
echo "<td id=\"start_date\">"."start date: "."</td>";
echo "<td id =\"end_date\">"."end date: "."</td>";
echo "<td></td>";
echo "</tr>";
?>
該行最初設置在文件隱藏準備通過以下的JQuery: -
$(function(){
$('.info_row').hide();// On document load I am hiding all the element with class info_row.
$('.toggler').toggle(function(){// Then I am toggling between hide and show.
var currentId = $(this).attr('id');
var number = currentId.substr(currentId.length - (currentId.length - currentId.indexOf("_") - 1));
var rowId = 'row_' + number;
$("#" + rowId).show();
}, function(){
var currentId = $(this).attr('id');
var lastChar = currentId.substr(currentId.length - (currentId.length - currentId.indexOf("_") - 1));
var rowId = 'row_' + lastChar;
$("#" + rowId).hide();
});
});
我不能夠實現切換,即該行不隱藏和顯示,因爲我是試圖實現。
任何幫助將不勝感激。
'.toggler'類應用於哪裏? – 2013-03-14 06:19:27
該類是由php生成的另一個錶行的一部分,我也將添加該部分。抱歉。 – 2013-03-14 06:21:14
jquery必須在html頁面上進行初始化 – 2013-03-14 06:22:28