隐藏域是用来收集或发送信息的不可见元素,对于网页的访问者来说,隐藏域是看不见的。当表单被提交时,

隐藏域就会将信息用你设置时定义的名称和值发送到服务器上。

  HTML语言创建普通隐藏域  

<input type="hidden" name="hdncount" value="值">   JavaScript语言创建隐藏域   <script>   function add(value)   {   var value= 1   document.all.divHidden.innerHTML="<input type=hidden name=hdncount value=" + value+ ">";   }   </script>   注意:   表单提交时因为隐藏域的ID是一样的,在多个隐藏域时,提交到action或者接收页面的为数组的形式。

 

例子如下:

前台给商品打分后动态设置隐藏域的值,后台获取隐藏域值进行操作

rating.js

/*商品评分效果*/
$(function () {
    //通过修改样式来显示不同的星级
    $("ul.rating li a").click(function () {
        var title = $(this).text().trim();

        alert("您给此商品的评分是:" + title + "分");
       
        //var rate = $("Rate");
        //rate[0].value = title;
        var cl = $(this).parent().attr("class");
        $(this).parent().parent().removeClass().addClass("rating " + cl + "star");
        $(this).blur(); //去掉超链接的虚线框
        //设置隐藏域的值,使用jquery包装集的方法
        $("#Rate").attr("value", title);
        //使用原生js方法
       // document.getElementById("Rate").attributes["value"].value = title;
        return false;
    })
})

                   前台:

                   <div class="askFitem userQuestionsItem">
                        <span class="label userQuestionslabel">描述:</span>
                            <span>尺寸:</span><%=Html.DropDownList("SizeSuitable") %>
                            <span>颜色:</span><%=Html.DropDownList("ColorSuitable") %>
                            <span>质量:</span><%=Html.DropDownList("QuanlitySuitable") %>
                            <span>舒适:</span><%=Html.DropDownList("ComfortSuitable") %>
                    </div>

                    <div >
                        <span class="label userQuestionslabel">给商品评分:</span>
                       
                        <div class="pro_rating">
                            <ul class="rating nostar">
                                <li class="one">
                                <a title="1分"  href="#">1</a>
                                </li>
                                <li class="two">
                                <a title="2分" href="#">2</a>
                                </li>
                                <li class="three">
                                <a title="3分" href="#">3</a>
                                </li>
                                <li class="four">
                                <a title="4分" href="#">4</a>
                                </li>
                                <li class="five">
                                <a title="5分" href="#">5</a>
                                </li>
                            </ul>
                            <input type="hidden" name="Rate" id="Rate" value="" /> <span> (请给出你心中合适的评分)</span>
                        </div>
                       
                    </div>

   后台:

{

            if (Request.Form["Title"] != null && Request.Form["Body"] != null)
            {
                Comment comment = new Comment();
                comment.Title = Request.Form["Title"];
                comment.Body = Request.Form["Body"];
                comment.SizeSuitable = Request.Form["SizeSuitable"];
                comment.ColorSuitable = Request.Form["ColorSuitable"];
                comment.QualitySuitable = Request.Form["QuanlitySuitable"];
                comment.ComfortSuitable = Request.Form["ComfortSuitable"];

                if (Request.Form["Rate"]!=null)
                {
                    Rating rating = new Rating();
                    rating.Rate = Convert.ToDouble(Request.Form["Rate"]);
                    var i = rating.Rate;
                }
            }

}

以上代码为商品评分的部分代码,有问题可以问我,我会尽量回答。

posted on 2011-05-09 11:40  露水丛生  阅读(12033)  评论(0编辑  收藏  举报