小编Pap*_*apa的帖子

JavaScript AND(&&)运算符给出了非法字符错误,然后是另一个错误

我正在构建一个代码块,并遇到了一个问题,这使我很好奇为什么为什么&符不会从WordPress文本编辑器视图进行编码。这段代码按预期工作,当通过文本编辑器直接嵌入到页面中时,它会向我发出警报:

// This code works as expected
<script>
jQuery(document).ready(function() {
    if (jQuery('select[name=idx-q-PropertyTypes]:first').val()=='') {alert ('it exists');} else {alert ('cant find it');} 
    jQuery('.dsidx-resp-area-submit input').click(function(e){
        alert ("you clicked it");
        if (jQuery('select[name=idx-q-PropertyTypes]:first').val()=='') {
            alert ('There were no search parameters.');
            e.preventDefault();
        }
    });
});
</script>
Run Code Online (Sandbox Code Playgroud)

我想做的下一件事是检查条件并发。所以我将代码更改为此:

// This code gives errors 
<script>
jQuery(document).ready(function() {
    if (jQuery('select[name=idx-q-PropertyTypes]:first').val()=='') {alert ('it exists');} else {alert ('cant find it');} 
    jQuery('.dsidx-resp-area-submit input').click(function(e){
        alert ("you clicked it");
    if (
        jQuery('select[name=idx-q-PropertyTypes]:first').val()=='' &&
        jQuery('select[name=idx-q-Cities]:first').val()=='' &&
        jQuery('input[name=idx-q-PriceMin]:first').val()=='' &&
        jQuery('input[name=idx-q-PriceMax]:first').val()=='' &&
        jQuery('select[name=idx-q-BedsMin]:first').val()=='' &&
        jQuery('select[name=idx-q-BathsMin]:first').val()=='' &&
        jQuery('input[name=idx-q-ImprovedSqFtMin]:first').val()=='' …
Run Code Online (Sandbox Code Playgroud)

javascript wordpress tinymce

5
推荐指数
1
解决办法
587
查看次数

标签 统计

javascript ×1

tinymce ×1

wordpress ×1