2012-05-14 45 views
0

我調用從輸入文本控制JavaScript函數(在一個PHP文件):打印HTML輸入屬性和變量在屏幕上的文件

<input name="first_name" id="first_name" size="30" maxlength="25" type="text" value="{$fields.first_name.value}" onblur="checkvalid(this);"> 

這是在JavaScript文件中的函數:

function checkvalid(control){ 
    alert(control); 
} 

現在我需要調試此控件並查看其屬性,變量和值(不使用Visual Studio,使用'eclipse')。所以我想我唯一的選擇是在屏幕上打印HTML輸入控件的屬性,但是當我做alert(控件)時,我得到「[object HTMLInputElement]」消息,而不是控件的屬性。

我該如何調試html控件?如果我不能,我怎樣才能打印它的屬性和變量?

+0

試試這個:alert(jQuery(control).html()); –

+0

感謝學習者,但我得到一個空白的消息.... – Rodniko

+0

取代控制到$控制,並試圖得到它.. –

回答

2

您引用的屬性實際上稱爲屬性。讓我們來創建一個函數,它將迭代元素的屬性,並將它們以一個格式良好的字符串列出並提醒。

function check(element) { 
    var attrs = element.attributes; 
    var output = ""; 

    for (var i = 0; i < attrs.length; i++) 
     output += attrs.item(i).name + ': ' + attrs.item(i).value + '\n'; 

    alert(output); 
} 

現在我們將爲您的元素調用它。它有id="first_name",所以我們可以使用document.getElementById

check(document.getElementById("first_name")); 
+0

哇!感謝您的時間和精力! – Rodniko

相關問題