简体   繁体   中英

Cannot read property 'prop' of undefined

I am having an error that I am not able to fix. It seems to me like a pretty simple error yet I am not able to fix it. I have made a form. In this form, there is an input (checkbox) that you have to click on to accept the privacy declaration. Yet when clicked on, and unclicked afterward. An error occurs.

I have already searched on StackOverflow to see if there are already question asked related to my problem. But all the questions that were asked were about React. And they did not answer my question. I have also looked into this error myself. But I was not able to fix it.

if (!$) {
  $ = jQuery;
}

function IsEmail(email) {
  var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]  {
  2,
  4
}) + $ / ;
return regex.test(email);
}

$(document).ready(function() {
  $('#dnSubmit').css({
    opacity: 0.3
  });
  $("input#dnAkkoord, input#vwAkkoord").on('click', function() {
    if ($(this).prop("checked")) {
      $("input#dnEmail, input#vwEmail").attr("placeholder", "Voer hier je e-mailadres in").prop("disabled", false);
      $("button#dnSubmit, button#vwSubmit").prop("disabled", false).css({
        opacity: 1
      });
    } else {
      $("input#dnEmail, input#vwEmail").attr("Vergeet niet eerst onze privacyverklaring te accoderen ...").prop("disabled", false);
      $("button#dnSubmit, button#vwSubmit").prop("disabled", true).css({
        opacity: 0.3
      });
    }
  });
});

I am expecting the error to go away. This will help me to work further on my form.

What exactly are you expecting this to return?:

.attr("Vergeet niet eerst onze privacyverklaring te accoderen ...")

With a single argument, .attr() returns the value of that attribute. But it seems very unlikely that your element has an attribute by that name. And even if it did, that value still wouldn't have a .prop() function.

Looking at the code above it, it seems like you meant to set the value of a placeholder attribute, which would then return a jQuery object:

.attr("placeholder", "Vergeet niet eerst onze privacyverklaring te accoderen ...")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM