2015-10-20 77 views
0

使用表单内的复选框,如下所示。实现复选框返回值

<form action="" method="get"> 
    <p> 
     <input type="checkbox" id="blunch" /> 
     <label for="blunch">Burrito Lunch</label> 
    </p> 
    <p> 
     <input type="checkbox" id="trip" /> 
     <label for="trip">Ski Trip</label> 
    </p> 
    <p> 
     <input type="checkbox" id="dance" /> 
     <label for="dance">Snowball Dance</label> 
    </p> 
    <button class="btn btn-primary btn-lg waves-effect waves-light" id="submit" type="submit">Submit</button> 
</form> 

当我尝试一下当复选框被选中的输出是什么,它只是显示为一个问号。有没有办法找出结果是什么名字?

+1

这是很清楚你所要求的。 “结果名称”是什么意思?复选框只能有布尔型“checked”属性。 –

+0

我的意思是如果方法得到,它会在栏中显示什么? @YeldarKurmangaliyev –

+0

因为现在它从 file:/// C:/Users/Abhi/Documents/material-design-template/www/index.html 到 file:/// C:/ Users/Abhi /文件/材料设计模板/网络/ index.html的? –

回答

1

name属性被用于标记消息中的字段发送到与HTTP(超文本传输​​协议)服务器GETPOST当你点击提交的形式。您必须通过name属性给name输入字段。你已经给了id这就是你面临问题的原因。

检查这个代码

<form action="" method="get"> 
    <p> 
     <input type="checkbox" id="blunch" name="blunch" /> 
     <label for="blunch">Burrito Lunch</label> 
    </p> 
    <p> 
     <input type="checkbox" id="trip" name="trip" /> 
     <label for="trip">Ski Trip</label> 
    </p> 
    <p> 
     <input type="checkbox" id="dance" name="dance" /> 
     <label for="dance">Snowball Dance</label> 
    </p> 
    <button class="btn btn-primary btn-lg waves-effect waves-light" id="submit" type="submit">Submit</button> 
</form>