2015-10-20 74 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>