2012-10-04 63 views
0
var generic_lookup_Enr_Rds_Section2009_selected = function(id, to_s) { 
    $(".cross-reference-section-value-id").text(id); 
    $(".cross-reference-section-value").text(to_s); 
    $(".cross-reference-section-value").css('display', 'inline'); 
    $("#modal_popup").dialog("destroy"); 
    $(".cross-reference-clear-img").removeData([id, to_s]); 
}; 

通過這個javascript,我把id和字符串,並存儲到我的html頁面中的標籤字段。現在,我通過css屬性隱藏了id。我只是爲了顯示字符串。我在字符串旁邊添加了一個清晰符號的圖像。當我點擊該圖像時,它應該清除ID和字符串字段並隱藏圖像圖標。如何在Ruby on Rails中隱藏javascript中的字段?

回答

1

不要隱藏id,只是爲了將它存儲在另一個地方而不是更容易。例如:

var generic_lookup_Enr_Rds_Section2009_selected = function(id, to_s) { 
    $("#cross-reference-section-value").data('id', id); 
             .text(to_s); 
             .css('display', 'inline'); 
    $("#modal_popup").dialog("destroy"); 
}; 

要訪問此屬性只需要使用相同的.data方法:

var id = $("#cross-reference-section-value").data('id'); 
+0

它是有道理的..非常感謝你。 – Vinay

+0

不客氣。 ) – raina77ow

+0

在同一個字段中,我有一個類名爲.cross-reference-clear-img的按鈕當我們單擊這個圖像時,我想清除該字段,並將id和字符串設置爲默認狀態。可能嗎? – Vinay

2

而且,一個小小的優化:您可以連接jQuery的功能速度

$("#cross-reference-section-value") 
    .data('id', id); 
    .text(to_s); 
    .css('display', 'inline'); 

即使此外,將$(「#cross-reference-section-value」)保存在變量中:

var my_div = $("#cross-reference-section-value") 
my_div 
    .data('id', id); 
    .text(to_s); 
    .css('display', 'inline'); 
+0

我編輯了我的問題,請幫助我 – Vinay

+1

$('。cross ('click',function(){$(「#cross-reference-section-value」)。text('')} –

相關問題