我正在嘗試用普通的 Javascript 模擬表單的數(shù)據(jù)輸入。我無法操作 HTML。我的代碼工作正常,直到單擊最后的保存按鈕,然后清除填寫的輸入。如何填寫輸入并確保單擊最后的“保存”按鈕時(shí)數(shù)據(jù)不會(huì)被清除?HTML:<input placeholder="What is the title" maxlength="50" type="text" data-vv-name="title" aria-label="form__text" class="form__text p--4" aria-required="true" aria-invalid="false"><textarea placeholder="Describe it! (required)" maxlength="500" data-vv-name="description" aria-label="form__text" class="form__text listing-editor__description__input p--3" aria-required="true" aria-invalid="false" style="height: 135px;"></textarea>JavaScript:if (document.querySelectorAll('.p--4')[0]) { document.querySelectorAll('.p--4')[0].value = "Wuthering Heights by Emily Bront?"; document.querySelector('.p--4').dispatchEvent(new Event('change', { 'bubbles': true }));}if (document.querySelectorAll('.p--3')[0]) { document.querySelectorAll('.p--3')[0].value = "Wuthering Heights is a novel by Emily Bront? published in 1847 under her pseudonym Ellis Bell. Bront?'s only finished novel, it was written between October 1845 and June 1846. Wuthering Heights and Anne Bront?'s Agnes Grey were accepted by publisher Thomas Newby before the success of their sister Charlotte's novel Jane Eyre. After Emily's death, Charlotte edited the manuscript of Wuthering Heights and arranged for the edited version to be published as a posthumous second edition in 1850."; document.querySelector('.p--3').dispatchEvent(new Event('change', { 'bubbles': true }));}
Javascript 輸入值在單擊按鈕時(shí)消失
呼啦一陣風(fēng)
2023-10-30 19:47:55