选择单选按钮时,表单应显示而无需重新加载页面

发布于 2024-11-18 19:40:34 字数 1027 浏览 4 评论 0原文

嗨,我是一名业余程序员。我想让表单动态显示,而无需在用户单击单选按钮后重新加载页面。有什么可以参考的吗?有人可以帮我解决这个问题吗?

这是 HTML 代码

<p>First Name: <input type="text" name="fname" size="15" maxlength="20"/> </p>

<p>Term <select name="term">
    <option value="noterm">No Term</option>
    <option value="1year">1 Year</option>

</select></p>

<p>Enter IMEI: <input type="text" name="imei" size="15" maxlength="20" value=""/> </p>
<p>Selling Price: <input type="text" name="sprice" size="15" maxlength="20" value=""/> </p>
<p>Rep: <input type="text" name="rep" size="5" maxlength="3" value=""/> </p>
<p><input type="submit"name="submit" value="Tender" /></p>


</form>
<!--This is where I need the action to HAPPEN-->
<form>
<input type="radio" name="Credit" value="ISC" /> ISC<br />
<input type="text" name="credit1" size="15" maxlength="10" value=""/>
</form>

Hi I am an amateur programmer. I want to have the form appear dynamically without reloading the page once user clicks the radio button. Is there any reference I can find. Can someone help me with this please.

Here's the HTML code

<p>First Name: <input type="text" name="fname" size="15" maxlength="20"/> </p>

<p>Term <select name="term">
    <option value="noterm">No Term</option>
    <option value="1year">1 Year</option>

</select></p>

<p>Enter IMEI: <input type="text" name="imei" size="15" maxlength="20" value=""/> </p>
<p>Selling Price: <input type="text" name="sprice" size="15" maxlength="20" value=""/> </p>
<p>Rep: <input type="text" name="rep" size="5" maxlength="3" value=""/> </p>
<p><input type="submit"name="submit" value="Tender" /></p>


</form>
<!--This is where I need the action to HAPPEN-->
<form>
<input type="radio" name="Credit" value="ISC" /> ISC<br />
<input type="text" name="credit1" size="15" maxlength="10" value=""/>
</form>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小巷里的女流氓 2024-11-25 19:40:34

最简单的方法是为您的 radio 输入和隐藏的 text 输入提供 id,然后使用以下 JavaScript:

document.getElementById("Credit").onclick = function() {
    document.getElementById("credit1").style.display = "block";
}

您将需要最初隐藏文本 input,您可以在 CSS 中使用 display:none 来完成此操作。您可以在此处查看示例。

如果您能够使用 jQuery,那就更容易了,无需将 id 添加到您的 input 元素,假设您的 name 属性是唯一的:

$("input[name=Credit]").click(function() {
    $("input[name=credit1]").show();
});

The easiest way will be to give your radio input and the hidden text input an id, and then use the following JavaScript:

document.getElementById("Credit").onclick = function() {
    document.getElementById("credit1").style.display = "block";
}

You will need to hide the text input initially, which you can do from in your CSS with display:none. You can see an example of that here.

If you are able to use jQuery it will be even easier, without adding an id to your input elements, assuming your name attributes are unique:

$("input[name=Credit]").click(function() {
    $("input[name=credit1]").show();
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文