2011-04-12 76 views
0

我有與定義如下文本字段的形式:jQuery的,獲得ID一個textarea

<textarea style="height: 60px; width: 100%;" name="F3414" id="F3414" rows="6" cols="80" wrap="virtual" class="frmTxa fckEditor"></textarea> 

我需要,使用jQuery,得到textarea的id(在這種情況下,F3414)。

我已經試過:

$('textarea .fckEditor').attr('id'); 
$('.fckEditor').attr('id');/... with no luck. 

任何想法?

非常感謝

回答

2
alert($('textarea.fckEditor').attr('id')); 

你在你原來的問題textarea .fckEditor之間的空間,並刪除它有所作爲

工作實例:here

+0

$('textarea.fckEditor')。attr('id');/$('textarea.frmTxa')。attr('id');/$('textarea.frmTxa')。attr('id');/$('。frmTxa .fckEditor')。attr('id');/$('。frmTxa.fckEditor')。attr('id');所有返回的undefined :-( – Olivier 2011-04-12 09:53:23

+0

非常感謝這個工作示例,假設我的應用程序「怪異」,並且它們加載表單的方式並不理想。在Firebug中使用控制檯沒有幫助...添加jQuery代碼在我的表單中工作就像一個魅力... $('textarea.fckEditor')。attr('id') – Olivier 2011-04-12 10:18:38

1

如果您正在使用的textarea的編輯,它不會被一次應用插件呈現爲一個文本。它可能是一個內容可編輯設置爲on的iframe。

使用螢火蟲檢查頁面源代碼並嘗試找出HTML結構。

+0

不知道你的HTML結構的意思。提供的HTML是我在使用FireBug時看到的HTML。爲了替換我的textarea編輯器,我需要得到它的ID。我可以對它進行硬編碼,但由於我有不同的表單和字段,因此根據類獲取id會更容易。 – Olivier 2011-04-12 09:15:16