Giter Club home page Giter Club logo

jform's Introduction

JForm

用于HTML的表单初始化赋值和表单数据提交的轻量级Jquery插件

类型 配置
text、textarea data-text="text"
checkbox data-text="checkbox"
select data-text="select"
radio data-text="radio"

表单赋值

目前只支持Json格式数据进行表单初始化

调用方式:

forms.resetValues(formID,jsonData);

Demo

<body>
<div>
    <form method="post" id="formDemo">
        <input name="first" type="text" data-text="text">
        <textarea name="firstArea" cols="20" rows="5" data-text="text"></textarea>
        <input type="checkbox" name="checkboxFirst" value="1" data-text="checkbox">1
        <input type="checkbox" name="checkboxFirst" value="2" data-text="checkbox">2
        <select name="selectFirst" data-text="select">
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
        </select>
        <input type="radio" name="radioFisrt" value="1" data-text="radio">1
        <input type="radio" name="radioFisrt" value="2" data-text="radio">2
    </form>
</div>
</body>
<script>
    $(function(){
        setValue();
        function setValue(){
            var json={first:"11",firstArea:"22",checkboxFirst:[1],checkboxSecond:[4],selectFirst:3,radioFisrt:2,radioSecond:2};
            forms.resetValues("formDemo",json);
        }
    });
</script>

获取表单值

最后获取得到的是Json对象

调用方式

forms.values(formID);

Demo

<body>
<div>
    <form method="post" id="formDemo">
        <input name="first" type="text" data-text="text">
        <textarea name="firstArea" cols="20" rows="5" data-text="text"></textarea>
        <input type="checkbox" name="checkboxFirst" value="1" data-text="checkbox">1
        <input type="checkbox" name="checkboxFirst" value="2" data-text="checkbox">2
        <select name="selectFirst" data-text="select">
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
        </select>
        <input type="radio" name="radioFisrt" value="1" data-text="radio">1
        <input type="radio" name="radioFisrt" value="2" data-text="radio">2
        <button onclick="getValue();">确定</button>
    </form>
</div>
</body>
<script>
     function getValue(){       
         forms.values("formDemo");
     }
  
</script>

以上


作者:@迹_Jason

**更新日期:**2016/07/07

**微信号:**zoeminghong

**微信公众号:**APPZone

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.