我使用jQuery的append()
,attr()
和text()
通過ajax調用向我的select元素添加選項。當我嘗試在W3驗證器上驗證我的頁面時,我發現使用append()
函數創建的元素出錯。下面是函數:爲什麼我的jQuery創建元素(選項)失敗html5驗證
$.post("blah.php", function(result) {
var places = result.split(" ");
$.each(places, function(key, value) {
$("#usrplaces")
.append($("<option><\/option>")
.attr("value", value)
.text(value.replace(/\+/g, " ")))
})
})
驗證器顯示4個錯誤:
Quote " in attribute name. Probable cause: Matching quote missing somewhere earlier. (2x)
Attribute value"" not allowed on element option at this point.
Element option without attribute label must not be empty.
爲什麼會出現錯誤?
能否請您創建一個小提琴? – 2014-09-01 06:09:05
ajax調用轉到需要會話數據的php頁面,我不認爲我可以在小提琴中工作。 – kungFuCoder 2014-09-01 06:12:57
向我們展示您正在驗證的代碼?我用JS代碼創建了一個JSFiddle:http://jsfiddle.net/cpr4kacq/2/,它看起來沒問題。 – Tomor 2014-09-01 06:14:38