2013-06-30 27 views
0

Dart CheckboxInputElement在開始和結束輸入標記之間添加指定文本,瀏覽器忽略此文本。例如,下面的鏢代碼:Dart CheckboxInputElement不顯示文本

FormElement form = new FormElement(); 
    CheckboxInputElement option = new CheckboxInputElement(); 
    option.name = "text1"; 
    option.value = "text1"; 
    option.text = "text1"; 
    form.children.add(option); 
    window.children.add(form); 

創建以下HTML代碼:

<form> 
    <input type="checkbox" name="text1" value"text1">text1</input> 
</form> 

我結束了沒有描述符的複選框。

回答

3

您必須添加一個標籤與描述符的文本,並將其鏈接到複選框:

FormElement form = new FormElement(); 
CheckboxInputElement option = new CheckboxInputElement(); 
option.name = "text1"; 
option.value = "text1"; 
option.id = "text1"; 
form.children.add(option);  
LabelElement label = new LabelElement(); 
label.htmlFor = 'text1'; 
label.text = "This is a checkbox label"; 
form.children.add(label); 
window.children.add(form); 

的財產將尋找指定的ID輸入並連接(使點擊標籤文本將切換複選框)。

你最終將與下面的HTML:

<form> 
    <input type="checkbox" name="text1" value="text1" id="text1"> 
    <label for="text1">This is a checkbox label</label> 
</form> 
+0

我認爲可以在不使用標籤元素被添加的描述符。總之,謝謝你的建議。它有訣竅。 –

+0

有趣。我不知道「htmlFor」將標籤綁定到複選框元素。 –