2013-03-15 25 views
0
<script> 
       function ShowCommentBox() { 
        $("#dialog").dialog({ modal: true }); 
       } 

       function GrabDetails() { 
        var obj = jQuery.parseJSON('{"name":"John"}'); 
        $("#item").val(obj.name); 
       } 
    </script> 

    <div id="dialog" title="Comments" style="display:none;"> 
    <table class="detailstable FadeOutOnEdit"> 
     <tr> 
      <th>Item</th> 
     </tr> 
     <tr> 
      <td><asp:Label ID="ItemIdLabel" Text="item" runat="server"/></td> 
     </tr> 
    </table> 
    </div> 

<input id="SubmitCommentsToInvoice" type="button" value="Comments" onclick="ShowCommentBox()" /> 

在我的asp.net項目中,當用戶單擊'註釋'按鈕時,div顯示包含標籤。 我試圖用JSON來顯示字符串「約翰」 - 存儲在他們#item對象在'GrabDetails()'存儲字符串並使用JSON抓取

然後在標籤text =「」我如何拉存儲的值#it​​em對象。

由於

+0

'$( 「#項目」)...'暗示有一個帶有id =「item」的html元素 - 我沒有看到它顯示的html。 – Igor 2013-03-15 14:23:05

回答

1

#item是jQuery中的ID選擇器,它有在這裏與ID 「項」 無元素。另外,<asp:Label />以不同的方式從服務器呈現爲html格式。但是,看起來你並沒有在服務器端使用這個標籤?如果是這樣的情況下,我只想讓一個HTML元素像

<td id="WhereNameGoes"></td> 

然後

function GrabDetails() { 
    var obj = jQuery.parseJSON('{"name":"John"}'); 
    $("#WhereNameGoes").text(obj.name); 
    // this still needs to be called somewhere, perhaps in ShowCommentBox()? 
} 

jQuery的$.val()則多爲<input />元素

+0

好人感謝 – Mick 2013-03-15 15:00:59