第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Javascript 輸入值在單擊按鈕時(shí)消失

Javascript 輸入值在單擊按鈕時(shí)消失

呼啦一陣風(fēng) 2023-10-30 19:47:55
我正在嘗試用普通的 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    }));}
查看完整描述

1 回答

?
慕虎7371278

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超4個(gè)贊

您的代碼示例似乎不完整,但我假設(shè)這些元素位于元素內(nèi)部form,按鈕是button帶有 的元素type="submit",并且按鈕位于表單內(nèi)部。


如果您想阻止提交按鈕發(fā)布表單,那么您需要阻止默認(rèn)行為:


const form = document.querySelector('form');


form.addEventListener('submit', (event) => {

  event.preventDefault();

  console.log('Do stuff here...');

});

<form>

  <button type="submit">Submit</button>

</form>


查看完整回答
反對(duì) 回復(fù) 2023-10-30
  • 1 回答
  • 0 關(guān)注
  • 159 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)