我这个简单的测试代码循环并显示数组中的内容。当我在浏览器中运行它时,它不会显示或运行任何错误。
$("#dropdownlist").kendoDropDownList().data("kendoDropDownList");
var dragging = false,
currentX = null,
currentW = null;
$("body")
.on("mousedown", ".k-dropdown-wrap", function(e) {
dragging = true;
currentX = e.clientX;
currentW = $(this).width();
})
.on("mouseup", ".k-dropdown-wrap", function() {
dragging = false;
})
.on("mousemove", function(e) {
if (dragging) {
var diff = currentX - e.clientX,
wrapper = $($("#dropdownlist").data("kendoDropDownList").wrapper);
wrapper.width((currentW - diff) + 20);
}
})
.on("mouseup blur focusout", function() {
dragging = false;
});
答案 0 :(得分:1)
使用以下行
更改就绪功能代码 $(document).ready(function(){
$.each(arr, function(index, value) {
task += value + "<br>";
$('div.content').html(task);
})});
答案 1 :(得分:0)
如document-ready文档中所述:
$( document ).ready(function() {
YOUR CODE HERE
});
所以你的代码应该是:
var arr = ["One", "Two", "Three", "Four", "Five"];
var task = "";
$(document).ready(function () {
$.each(arr, function (index, value) {
task += value + "<br>";
$('div.content').html(task);
});
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="content"></div>
&#13;
更短的形式是:
$(function () {
$.each(arr, function (index, value) {
task += value + "<br>";
$('div.content').html(task);
});
});