4
我試圖通過使用Tooltipster插件用戶的get和我運行自定義錯誤消息爲以下問題:jQuery驗證插件和Tooltipster插件錯誤
You called Tooltipster's "content" method on an uninitialized element
我的HTML代碼:
<form>
<input id="one" type="number" name="one" />
<input id="two" type="number" name="two" />
<button id="button" type="submit">Submit</button>
</form>
的Javascript:
$(document).ready(function() {
$('form').validate({ // initialize the plugin
rules: {
one: {
required: true,
min: 1,
max: 100
},
two: {
required: true,
min: 50,
max: 80
}
},
submitHandler: function (form) {
doTest();
return false;
},
errorPlacement: function (error, element) {
var lastError = $(element).data('lastError'),
newError = $(error).text();
$(element).data('lastError', newError);
if (newError !== '' && newError !== lastError) {
$(element).tooltipster('content', newError);
$(element).tooltipster('show');
}
},
success: function (label, element) {
$(element).tooltipster('hide');
}
});
});
可能是什麼問題?
我仍然得到同樣的錯誤。 – kalpetros
@kalpetros,[你可以看到,它的工作原理沒有錯誤](http://jsfiddle.net/2DUX2/3/)。 – Sparky
@kalpetros,你必須確保你正確定位你的輸入元素。嘗試改變'$('form input [type =「text」]')。tooltipster(...'to'$('form input')。tooltipster(...' – Sparky