Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript HTML表单操作_Javascript_Html_Forms_Text_Input - Fatal编程技术网

Javascript HTML表单操作

Javascript HTML表单操作,javascript,html,forms,text,input,Javascript,Html,Forms,Text,Input,对于输入样式“文本”,我有一个javascript函数,例如: document.getElementById("dds1").onkeyup = function() { updateIt(); }; 现在,如果我有一个复选框呢?代码是什么样子的?单选按钮呢?我将使用什么来获取值(对于复选框,选中或未选中。对于单选按钮,我希望获取单击的按钮) 以下是单选按钮的代码: <li id="foli517" class=" "> <label cla

对于输入样式“文本”,我有一个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>
document.getElementById("radioButton").onclick = function() { 
    var clickedId = this.id;
    //whatever 
};
  • 运输选择 2美元运费 我将取货(免费送货)
  • 复选框:

    document.getElementById("checkBox").onclick = function() { 
        var isChecked = this.checked; 
        //whatever
    };
    
    对于单选按钮:

    <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>
    
    document.getElementById("radioButton").onclick = function() { 
        var clickedId = this.id;
        //whatever 
    };
    

    我更新了代码。请看上面。如果用户选择了与“$2.00 shipping fee”对应的单选按钮,您能否实现执行以下操作的功能:document.getElementById(“shippingSpan”).innerHTML=“$2.00”@resing1您可以通过多种方式进行调整-假设每个单选按钮上都有一个id,最简单的方法是
    document.getElementById(“aSpecificRadioButton”).onclick=function(){document.getElementById(“shippingSpan”).innerHTML=“$dollarAmountForThatRadioButton”;}