2012-03-12 72 views
-3

对不起“阴天”的问题,很着急,很沮丧。jquery validation errorElement div with inner tags

我正在使用jquery验证,并希望创建提示看起来像验证消息。

通过(默认情况下其标签)提供errorElement我可以控制在HTML标签中的错误将被包含:

$( '形式')验证({errorElement: “格”});

为了创建提示看起来像div一样,我想放置更多的html标签。我可以通过自己包装信息来做到这一点,但我不喜欢这种方式。

所以我的问题是:有一种方法来嵌套errorElements或有另一个属性,可以用作模板?

谢谢,希望更清楚。

+1

后一些有效的HTML – DG3 2012-03-12 20:41:43

+0

什么是'errorElement'?! – gdoron 2012-03-12 20:41:52

回答

0

根据您的模糊问题,这里是一个示例。假设html如下所示:div最初是空的。这将有“P”标签来填充,如果用户没有在文本框中输入任何值

​<div id="errorDiv"></div> 

​<input type="text" name="name" value=""/> 
<button type="button">Submit</button>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​ 

jQuery代码:

​$(document​).ready(function(){ 

    $("button").on("click",function(){ 
     //check if the textbox value is empty. if its empty, then update the innerhtml of the div. 
     if($("input[name='name']").val() === ""){ 
      $("#errorDiv").html("<p>Enter Some Text</p>"); 
     } 
     else { 
      $("#errorDiv").html(""); 
     } 
    });   
});​