javascript - 如下代码如何修改,才可以达到同一个页面有多个输入框,也可以进行验证?
黄舟
黄舟 2017-04-10 14:46:29
0
4
325

下面这个代码就是检测输入框有字才可以点击,缺点是只能验证1个输入框
但是我的页面排版像微博一样,同一个页面有多个输入框。求教大神怎么改才可以适用于多个输入框呢?
http://jsbin.com/gunigaxuwa/1/edit?html,css,js,output

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(4)
迷茫

思路:

<input type="text" name="title" id="title" value="title" />
<input type="text" name="name" id="name" value="name" />
<input type="text" name="content" id="content" value="content" />
<input type="text" name="phone" id="phone" value="phone" />
<button id="button">点我</button>

$('#button').click(function(){
        var json = {'title':'标题必填','name':'姓名必填','content':'内容必填','phone':'电话必填'};
        for (var i in json) {
            if ($('#'+i).val() == '') {
                console.log(json[i]);
            }
        }
    })
左手右手慢动作

不考虑直接用插件么 jqueryvalidation

http://jsfiddle.net/fineliu/hngah03b/

Ty80

直接 jquery validation 还考虑神马

黄舟

多谢各位,刚才又研究了一下,也搞出一个结果
http://jsbin.com/sucaxekopa/1/edit?html,css,js,output
用for循环去找对应的输入框然后再判断

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!