我想插入一个Cookie通知栏。现在在旧的时事通讯页面上,我收到如下错误:
未捕获错误:语法错误,无法识别的表达式:li / label
来自简报的以下代码是
if( document.addEventListener ) document.addEventListener( 'DOMContentLoaded', cmxform, false );
function cmxform(){
// Hide forms
$( 'form.cmxform' ).hide().end();
// Processing
$( 'form.cmxform' ).find( 'li/label' ).not( '.nocmx' ).each( function( i ){
var labelContent = this.innerHTML;
var labelWidth = document.defaultView.getComputedStyle( this, '' ).getPropertyValue( 'width' );
var labelSpan = document.createElement( 'span' );
labelSpan.style.display = 'block';
labelSpan.style.width = labelWidth;
labelSpan.innerHTML = labelContent;
this.style.display = '-moz-inline-box';
this.innerHTML = null;
this.appendChild( labelSpan );
} ).end();
// Show forms
$( 'form.cmxform' ).show().end();
}
//function to check empty fields
function isEmpty(strfield1, strfield2) {
strfield1 = document.forms.newsletter_subscribe.nome.value
strfield2 = document.forms.newsletter_subscribe.email.value
if (strfield1 == "" || strfield1 == null || !isNaN(strfield1) || strfield1.charAt(0) == ' ')
{
alert("Please insert your name!")
return false;
}
if (strfield2 == "" || strfield2 == null || strfield2.charAt(0) == ' ')
{
alert("Please insert a valid Email!")
return false;
}
return true;
}
//function to check valid email address
function isValidEmail(){
validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
strEmail = document.forms.newsletter_subscribe.email.value;
// search email text for regular exp matches
if (strEmail.search(validRegExp) == -1)
{
alert('Email not valid! Please retry!');
return false;
}
return true;
}
//function to check privacy
function Privacy()
{
if (document.forms.newsletter_subscribe.checkbox.checked==false)
{
alert('Please accept the privacy conditions!');
return false;
}
return true;
}
//function that performs all functions, defined in the onsubmit event handler
function check(){
if (isEmpty()){
if (isValidEmail()){
if (Privacy()) {
return true;
}
}
}
return false;
}
//**********************************************************************************************
//function to check empty fields unsubscribe form
function isEmptyEmail(strfield1) {
strfield1 = document.forms.newsletter_unsubscribe.email.value
if (strfield1 == "" || strfield1 == null || !isNaN(strfield1) || strfield1.charAt(0) == ' ')
{
alert("Please insert a valid Email!")
return false;
}
return true;
}
//function to check valid email address
function isValidEmailCancel(){
validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
strEmail = document.forms.newsletter_unsubscribe.email.value;
// search email text for regular exp matches
if (strEmail.search(validRegExp) == -1)
{
alert('Email not valid! Please retry!');
return false;
}
return true;
}
//function that performs all functions, defined in the onsubmit event handler
function check_unsubscribe(){
if (isEmptyEmail()){
if (isValidEmailCancel()){
return true;
}
}
return false;
}
删除新资源时,该新闻稿脚本没问题。但是,当使用新的jQuery资源时会失败。
答案 0 :(得分:0)
如果你想在jQuery中连接多个选择器,发现你使用了错误的语法
$( 'form.cmxform' ).find( 'li/label' ).not( '.nocmx' ).each( function( i ){
应该成为:
$( 'form.cmxform' ).find( 'li, label' ).not( '.nocmx' ).each( function( i ){
这意味着您正在寻找您选择的DOM范围内的任何li OR标签标签(' form.cmxform')