2012-07-31 66 views
0

我需要在javascript中獲取styleClass元素的值。頁面在jsp中使用struts/html標籤元素。 JSP代碼是如何獲取html struts styleClass與javascript/jquery

<input type="hidden" class="filename" name="filename" value="<%= filename %>" /> 
         <html:file property="testfile" styleClass="testfile"/> 

和按鈕的onclick我調用的JavaScript

function fields() { 
    var filename = jQuery('.filename'); 
    alert(filename); 
    var testfile= jQuery('.testfile').val(); 
    alert(testfile); 
    } 

然而,在firstcase(文件名),我得到[對象的對象]返回並在第二種情況下,我得到「未定義」。有人可以給一些關於如何獲取上傳的文件名在jQuery中的指針。由於

回答

0

試試這個

var testfile= jQuery('.testfile').attr('value'); 

出於安全原因,您的瀏覽器可能會阻止訪問value屬性。在不同的瀏覽器中嘗試這兩種選項 - Chrome,Firefox,IE等。