Twitter bootstrap 验证错误时提交后在div中添加类
验证错误时提交后在div中添加类 我的代码是:Twitter bootstrap 验证错误时提交后在div中添加类,twitter-bootstrap,cakephp-2.0,Twitter Bootstrap,Cakephp 2.0,验证错误时提交后在div中添加类 我的代码是: <div class="control-group"> <label class="control-label">Name</label> <div class="controls"> <?php echo $this->Form->input('name', array('type'=>'text','label' => false,
<div class="control-group">
<label class="control-label">Name</label>
<div class="controls">
<?php echo $this->Form->input('name', array('type'=>'text','label' => false, 'pattern' => "^[a-zA-Z][a-zA-Z ]{4,}$",
'title' => "Minimum 5 letters.", "id" => "name",
'placeholder' => 'Enter your Name', 'required' => true,)); ?>
</div>
</div>
名称
但是,如果验证失败,我希望在表单提交后执行此操作:
<div class="control-group error">
<label class="control-label">Name</label>
<div class="controls">
<?php echo $this->Form->input('name', array('type'=>'text','label' => false, 'pattern' => "^[a-zA-Z][a-zA-Z ]{4,}$",
'title' => "Minimum 5 letters.", "id" => "name",
'placeholder' => 'Enter your Name', 'required' => true,)); ?>
</div>
</div>
名称
一种方法是使用javascript添加类。。例如,你可以做如下事情
<div class="control-group" id="THISELEMENT">
<label class="control-label">Name</label>
<div class="controls">
<?php echo $this->Form->input('name', array('type'=>'text','label' => false, 'pattern' => "^[a-zA-Z][a-zA-Z ]{4,}$",
'title' => "Minimum 5 letters.", "id" => "name",
'placeholder' => 'Enter your Name', 'required' => true,)); ?>
</div>
</div>
<script>
document.getElementById("THISELEMENT").className += " error";
</script>
名称
document.getElementById(“thiseElement”).className+=“error”;
将id添加到div,然后使用jQuery可以添加类$(“#ID_值”).addClass(“错误”);我看到了你所说的例子,但是如果在cakephp中有任何条件方法,这个问题对你有帮助吗?你应该退房