Change input value with Javascript

前端 未结 2 1413
小鲜肉
小鲜肉 2021-01-21 03:16

The title seems easy, but I need help.

I have a form with a field input \"email\" of which value is null until the user fills it up. Okay, on click of the submit button,

相关标签:
2条回答
  • 2021-01-21 03:36

    Try this email.value = 'Insert a correct email'; instead of email.setAttribute('value','Insert a correct email');

    0 讨论(0)
  • 2021-01-21 03:55

    It's good that you were trying to use setAttribute at all because it's an important method, but the problem is that you don't want to modify the value attribute in this case, which is a part of the DOM, but you want to modify the <input> element's value property.

    email.value = 'Insert a correct email';
    

    http://jsfiddle.net/XJZwm/

    0 讨论(0)
提交回复
热议问题