gpt4 book ai didi

javascript - PHP 当用户选中复选框时清除文本框

转载 作者:行者123 更新时间:2023-11-28 00:06:33 25 4
gpt4 key购买 nike

目前我正在尝试添加一些功能,以便用户能够提交匿名建议。当用户选中复选框时,我试图清除包含用户名的文本框。但是,我的代码在选中时不会清除该复选框。有没有办法在提交表单之前清除复选框?

谢谢

<div>
<label style="display: inline-block; margin-left: 10px; letter-spacing: 2px; color: #007A8E;">
<div align="left"><b>Name:</b> </div>
</label>
<div align="left">
<input type="checkbox" style=" margin-left: 110px; outline: 1px solid #0078AE; " name="Anonymous" value="Anonymous" onClick="CheckAnon">
</div>
<label style="margin-left: 2px; color: #0078AE;">
<div align="left">Anonymous</div>
</label>
<div align="left">
<?
function CheckAnon()
{
if(isset($_POST['Anonymous']) == 'Anonymous')
{
$anonFirstName="Anon";
$anonLastName="Anon";
}
else if (isset($_POST['Anonymous']) != 'Anonymous')
{
$anonFirstName = $firstName;
$anonLastName= $lastName;
}
}
?>
</div>
</div>

<div align="left">
<input name="firstname" style="height: 34px; width: 268px; margin-left: 10px; margin-top: 5px; color: #007A8E;
border: 1px solid #dedede; -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px;" type="text"
value="<? echo $anonFirstName?> <? echo $anonLastName?>">
</div>

最佳答案

您可以使用 jquery 或 javaScript 在客户端执行此操作。

假设这个文本框:

  <input type="text" id="fname" />

JavaScript 方法:

<script type="text/javascript">

function clearTextBox() {

// Code to clear textbox on Checkbox tick

var textname = document.getElementById("fname"); //get textbox id
textname.value = ""; // clear the textbox
}
</script>

关于javascript - PHP 当用户选中复选框时清除文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31292782/

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