我想設置一個函數內的函數傳遞onClick時的JavaScript值,然後我想我的函數採取點擊目標的ID保存到一個var,所以我可以基於其返回的javascript var id在該對象上調用.show。Django + Jquery + Tabs,標籤不會顯示在點擊
這是我如何輸出列表鏈接:
{%for stat in ip_new_list %}
{% if 'Newip' in stat%}
<li class="active"><a href onClick="showTable();" id='{{stat.1}}'>{{stat.1}} </a></li>
{%endif%}
{%endfor%}
</ul>
我隱藏所有與類名使用下面的代碼標籤:
$(document).ready(function(){
$('#loading').hide();
$('#helppage').hide();
$('.iptable').hide();
});
這是我的代碼爲了顯示帶有被點擊鏈接的ID的div標籤,我已經驗證了div標籤id匹配鏈接id,該鏈接id是那種格式的'100.000.000.000'ip地址。
function showTable(clicked){
console.log("ShowTableClicked");
console.log(clicked.id);
var clickedID = "#" + clicked.id;
$(clickedID).show();
console.log(clickedID);
}
這裏是我的Django/HTML代碼:
<ul>
{%for stat in ip_new_list %}
{% if 'Newip' in stat%}
<li class="active" id={{stat.1}}><a href='#' onClick="showTable(this);" id={{stat.1}}>{{stat.1}}</a></li>
{%endif%}
{%endfor%}
</ul>
{%for stat in ip_new_list %}
{% if 'Break' in stat%}
</div> <div id="{{stat.1}}" class='iptable'>
{%endif%}
{% if 'First' in stat%}
<div id="{{stat.1}}" class='iptable'>
{%endif%}
{{stat.0}} | {{stat.1}} | {{stat.2}} <br>
{%endfor%}
這裏是控制檯輸出:
"ShowTableClicked" ipreport:56
"000.000.000.000" ipreport:57
"#000.000.000.000"
但div標籤仍然沒有出現我用調試檢查員驗證div標籤是否有正確的ID。請讓我知道你是否可以找出原因。
'$( '#' + clickedID).show();' – bencripps 2014-09-06 02:15:48