zoukankan      html  css  js  c++  java
  • 通过表单隐藏域向后台传值

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

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

      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;
                    }
                }

    }

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

  • 相关阅读:
    Static Linking versus Dynamic Linking
    C keywords are overloaded with serveral meanings
    深圳立体地图查查吧http://sz.chachaba.com/api.html
    What's a Declaration? What's a Definition?
    jQuery Template and Data Linking
    XPath
    singleton及多线程验证,所有线程完成才继续运行WaitHandle
    jquery文本框只输入数字插件
    UVA 993 Product of digits
    HDU 1879 继续畅通工程
  • 原文地址:https://www.cnblogs.com/lushuicongsheng/p/2040994.html
Copyright © 2011-2022 走看看