我想包括这个正则表达式条件并激活下面发布的javascript函数中的分析代码(如果它符合正则表达式条件)。条件语法帮助
if (/^[abc].*/i.test(mystring)) {
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXX-XX']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
alert('Congrats ABC!');
}
现在,我怎么在里面添加上述(正则表达式条件和分析)的代码?
另请注意。下面的部分目前完美。
function validateCoupon(form){
var mystring = document.getElementById('textCoupon').value;
if(form.textCoupon.value.length)
{
// validate coupon
$.get("/include/checkItOut.php", { coupon: form.textCoupon.value }, validateShipping);
alert('Performed the check and matched');
}
else
{
form.textCoupon.style.border = '';
validateShipping("yes");
alert('You Did Not Use Any Code');
}
return false;
}
换句话说。以某种方式将Regex条件和分析触发器包含在这里。
什么“现在我该如何添加上面的代码?”意思? – 2011-03-11 16:50:42
我试图在下面的代码中包含这个部分if(/^abc$/i.test ...没有成功,它可能是一个语法或条件问题,对此有什么建议吗? – detonate 2011-03-11 17:00:12
在'if(/^abc $/i.test(mystring);){',从'if()'中移除';'。 – 2011-03-11 17:05:15