gpt4 book ai didi

javascript - 在javascript中重置文本框值

转载 作者:IT王子 更新时间:2023-10-29 03:00:05 25 4
gpt4 key购买 nike

如果我有这样的输入文本框:

<input type="text" id="searchField" name="searchField" />

如何使用 javascript 或 jQuery 设置文本字段的值?

你会认为这很简单,但我已经尝试了以下方法:

使用默认值

var a = document.getElementById("searchField");
a.value = a.defaultValue;

使用 jQuery

jQuery("#searchField").focus( function()
{
$(this).val("");
} );

使用js

document.getElementById("searchField").value = "";

他们都没有这样做... :/

最佳答案

在 JavaScript 中:

document.getElementById('searchField').value = '';

在 jQuery 中:

$('#searchField').val('');

应该这样

关于javascript - 在javascript中重置文本框值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7174265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com