如何在joomla中进行javascript验证?
答案 0 :(得分:-1)
使用JHTML::_('behavior.formvalidation');
这是Joomla's tuturial for adding validation。唯一的区别是您必须复制invalid
类的CSS,它会在值无效时突出显示文本框。
另外,我个人的偏好。而不是编码<form ... onsubmit="return jsFunction()">
我喜欢这样做:
<script type="text/javascript">
window.addEvent('domready', function(){
// Add submit event to the form
$('myForm').addEvent('submit', function(e){
// Default check
var isValid = document.formvalidator.isValid(frm);
// Do additional checks + create message
var msg = '';
if (!isValid){
msg = 'Some values are not acceptable. Please retry.';
}else if($('some-other-value').value == 0){
msg = 'Select IO';
isValid = false;
}
if (!isValid){
// Stop event
new Event(e).stop();
// Somekind of invalid form handler... can do effects in here, etc...
handleInvalidForm(this, e, msg);
}
//
return isValid;
});
});
</script>