HTML 表单操作

发布于 2024-10-14 20:07:10 字数 1237 浏览 1 评论 0原文

对于输入样式“文本”,我有一个 javascript 函数,例如:

document.getElementById("dds1").onkeyup = function() {

    updateIt();
};

现在,如果我有一个复选框怎么办?代码会是什么样子?单选按钮怎么样?我将使用什么来获取值(对于复选框,选中或不选中。对于单选按钮,我想获取单击了哪个按钮)。

这是单选按钮的代码:

<li id="foli517"        class="     ">
<label class="desc" id="shippingChoice" for="Field517_0">
    Shipping Options
        </label>
<div>
<input id="shippingChoice" name="Field517" type="hidden" value="" />
    <span>
<input id="shipping1"       name="Field517"         type="radio"        class="field radio"         value="$2.00 Shipping Fee"      tabindex="13"                        checked="checked"                      />
<label class="choice" for="Field517_0"      >
    $2.00 Shipping Fee</label>
    </span>
    <span>
<input id="Field517_1"      name="Field517"         type="radio"        class="field radio"         value="I will pick up the items (free shipping)"        tabindex="14"                               />
<label class="choice" for="Field517_1"      >
    I will pick up the items (free shipping)</label>
    </span>
    </div>
</li>

For input style "text", I have a javascript function such as:

document.getElementById("dds1").onkeyup = function() {

    updateIt();
};

Now, what if I had a checkbox? What would the code look like? What about for radio buttons? What would I use to get values (for the checkbox, either checked or not checked. and for the radio buttons, I'd like to get which button is clicked).

Here is code for the radio button:

<li id="foli517"        class="     ">
<label class="desc" id="shippingChoice" for="Field517_0">
    Shipping Options
        </label>
<div>
<input id="shippingChoice" name="Field517" type="hidden" value="" />
    <span>
<input id="shipping1"       name="Field517"         type="radio"        class="field radio"         value="$2.00 Shipping Fee"      tabindex="13"                        checked="checked"                      />
<label class="choice" for="Field517_0"      >
    $2.00 Shipping Fee</label>
    </span>
    <span>
<input id="Field517_1"      name="Field517"         type="radio"        class="field radio"         value="I will pick up the items (free shipping)"        tabindex="14"                               />
<label class="choice" for="Field517_1"      >
    I will pick up the items (free shipping)</label>
    </span>
    </div>
</li>

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

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

发布评论

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

评论(1

云淡月浅 2024-10-21 20:07:10

对于复选框:

document.getElementById("checkBox").onclick = function() { 
    var isChecked = this.checked; 
    //whatever
};

对于单选按钮:

document.getElementById("radioButton").onclick = function() { 
    var clickedId = this.id;
    //whatever 
};

For the checkbox:

document.getElementById("checkBox").onclick = function() { 
    var isChecked = this.checked; 
    //whatever
};

For the radio button:

document.getElementById("radioButton").onclick = function() { 
    var clickedId = this.id;
    //whatever 
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文