如何在段落标记中显示隐藏字段值

时间:2013-10-03 09:06:15

标签: javascript jquery html

我想在

中显示hiddentfield值
 <p style="color: Red">
    Please note that you have <span>
       javascript:$("input[id$=hdnCartCount]").val();
   </span> more pending orders.
     <br />
      Click Checkout to proceed!
 </p>

我该如何显示?

2 个答案:

答案 0 :(得分:4)

假设您希望这是动态的,请稍微重新排列您的HTML(记下我给您的跨度的ID):

 <p style="color: Red">
    Please note that you have 
    <span id="pendingOrdersCount"></span> 
    more pending orders.
    <br />
    Click Checkout to proceed!
 </p>

然后你可以这样做:

<script type="text/javascript">

$(function () {
    $("#pendingOrdersCount").text($("input[id$=hdnCartCount]").val());
});

</script>

DEMO

答案 1 :(得分:0)

尝试向提供 ID

$("#spanId").text($('#hdnField').val());