简体   繁体   English

javascript验证

[英]Validation in javascript

this is the scenario, I have this form HTML 这是场景,我有此表单HTML

<form class="mainForm" name="eform" id="eform" action="/itg/sc_cust_maint_pkg.cust_dml"         method="get">
<div id="tab1" class="tab_content">
<div class="rowElem noborder"><label>Customer ID:</label>
<div class="formRight240">
<input type="text" name="p_cust_id_c" id="req" class="validate[required,maxSize[30]]"/>
</div></span><div class="fix"></div>

What I have to do is validate the required input, and add asterisk to the label,the working mode is to fix the problems using what we have, so I have to find a solution using just this. 我要做的是验证所需的输入,并在标签上添加星号,工作模式是使用已有的内容来解决问题,因此我必须使用此方法来找到解决方案。 the million question is, how to validate if p_cust_id_c is required using that class, and once do that then add an asterisk to the label. 百万的问题是,如何使用该类来验证是否需要p_cust_id_c,然后执行一次,然后在标签上添加一个星号。

Get the elements, check if the inputs class contains the string required , then add something to the label ? 获取元素,检查输入类是否包含required的字符串,然后在标签中添加一些内容?

var form  = document.getElementById('eform');
var input = document.getElementById('req');
var label = form.getElementsByTagName('label')[0];

if (input.className.indexOf('required') != -1) {
    label.innerHTML = label.innerHTML + '***';
}

FIDDLE 小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM