我设计了一项关于 Limesurvey (2.05+) 的调查,我们向受访者询问他们工作所在公司的名称。如果他们输入诸如“拒绝”、“拒绝”、“不能透露”等字样,我希望弹出警报并阻止他们继续。我在 Limesurvey 论坛上联系了这些人,他们给了我一些代码来尝试. 该代码适用于 Safari 和 IE,但不适用于 Chrome 或 Firefox。Limesurvey 技术在他身上进行了测试,他说它可以在他的 Chrome 上运行。我清除了所有缓存,重新启动浏览器,重新启动计算机……在我工作的 VPN 之外尝试……让其他人尝试……无济于事。
这是代码:
$(document).ready(function() {
// Identify this question
var thisQuestion = $('#question{QID}');
// Define the disallowed strings and allert text
var disallowed = ['refused', 'none of your business', 'nunya'];
var alertText = 'You have entered an invalid string!';
// Interrupt the Next/Submit click
$('#movenextbtn, #movesubmitbtn').bind('click', function () {
var thisInput = $('input.text', thisQuestion);
var thisVal = thisInput.val();
thisInput.removeClass('disallowed-string');
// Loop through all disallowed strings
$(disallowed).each(function() {
// If disallowed string found in input value
if(new RegExp('\\b'+this+'\\b', 'i').test(thisVal) == true) {
thisInput.addClass('disallowed-string'); // Add a class
alert(alertText); // Pop up alert
return false; // Exit the loop
}
});
// Abort the Next/Submit if we found a disallowed string
if(thisInput.hasClass('disallowed-string')) {
return false;
}
});
});
Firefox 或 Chrome 不喜欢这段代码的原因是什么?我有来自 Lynda.com 课程的其他代码,这些代码也不适用于 Chrome,但适用于 Safari。我们可以试试 jquery-validate 插件吗?我怎么能适应我的情况呢?
任何帮助,将不胜感激。让我知道您是否需要访问调查以进行检查。
提前致谢。
Ĵ