gpt4 book ai didi

javascript - 尝试清除 html javascript 中的字段

转载 作者:行者123 更新时间:2023-12-03 05:04:44 29 4
gpt4 key购买 nike

我正在尝试制作一个按钮来清理页面的特定字段。这就是我所拥有的,但它不起作用。不知道还能做什么。有些人试图帮助我对另一个主题的推荐,但由于我无法使其发挥作用,所以我提出了这个新问题。

谢谢

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Landing Page</title>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

<script>

$('.clear').on('click', function () {
$('#inputFirstName').val('');
$('#inputLastName').val('');
$('#inputEmail').val('');
});

</script>

<style>
#formTable {
/*border: 1px solid black;*/
margin: 0 auto;
}

#outer {
width: 100%;
height: 700px;
display: flex;
align-items: center;
/*background-color: gray;*/
}

#inner {
width: 300px;
height: 350px;
margin: 0 auto;
/*background-color: yellow;*/
}
</style>

</h:head>

<h:body>

<div id="outer">
<div id="inner">

<h:form class="signupform">

<p>Sign-up for more:</p>

<table id="formTable">
<tr>
<td>First Name:</td>
<td><h:inputText id="inputFirstName" value="#{visitor.firstName}"/></td>
</tr>
<tr>
<td>Last Name:</td>
<td><h:inputText id="inputLastName" value="#{visitor.lastName}"/></td>
</tr>
<tr>
<td>Email:</td>
<td><h:inputText id="inputEmail" value="#{visitor.email}"/></td>
</tr>
</table>


<p><h:commandButton id="submit" value="Submit" action="#{visitor.registerVisitor()}"/>
<h:outputText id="outputText" value="#{visitor.result}"/></p>

</h:form>

<button class="clear">Clear</button>

</div>
</div>

</h:body>
</html>

最佳答案

您正在调用 $('.clear')在元素存在之前。

因此,您要将事件处理程序添加到一个空集中。

您需要运行 <script> block 在元素之后。

关于javascript - 尝试清除 html javascript 中的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42058405/

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