jQuery:为什么不触发警报? [英] jQuery: why isn't this alert firing?

查看:85
本文介绍了jQuery:为什么不触发警报?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

损坏的演示: http://jsfiddle.net/sTzCS/52/

如果您去摆弄小提琴,则应该能够将列表中的团队拖放到新的顺序中.您还可以输入一个值,您认为每个团队在赛季中将获得的积分数量.完成排列后,jQuery会读取排序顺序,并且还会尝试获取每个团队的输入值.

If you go to the fiddle, you should be able to drag and drop the teams in the list into a new order. You can also input a value for the amount of points you think each team will get over the season. The jQuery reads the sort order after you finish rearranging them, and it also tries to get the input value for each team.

小提琴中的警报(我为测试目的而创建)旨在显示您处于第一位置的团队以及希望他们获得的积分.但是,警报不会触发. jLint说代码是有效的.我正在使用警报来确保我实际上得到了正确的值.您能解释一下为什么警报不起作用吗?

The alert (that I created for testing purposes) in the fiddle is supposed to show the team that you put in first position and the amount of points you expected them to get. However, the alert's not firing. jLint says the code is valid. I'm using the alert to make sure that I'm actually getting the right values. Can you explain why the alert's not working?

<form<form id="new_entry">

<ul id="sortlist">

        <li id="Vancouver">Canucks<input type="text" name="name" id="vanpoints"></li>
        <li id="Toronto">Toronto<input type="text" name="name" id="torontopoints"></li>
        <li id="Montreal">Montreal<input type="text" name="name" id="montrealpoints"></li>
        <li id="Ottawa">Ottawa<input type="text" name="name" id="ottawapoints"></li>
        <li id="Calgary">Calgary<input type="text" name="name" id="calgarypoints"></li>
        <li id="Edmonton">Edmonton<input type="text" name="name" id="edmontonpoints"></li>
        <li id="Winnipeg">Winnipeg<input type="text" name="name" id="winnipegpoints"></li>
</ul>
<input type="submit" value="Add">
</form>

jQuery

$("#sortlist").sortable({
    stop: function(event, ui) {
        result = $("#sortlist").sortable("toArray");
        var attributes;
        attributes = {
            first: { team: result[0].id, value: result[0].children()[0].val() },
       second : { team: result[1].id, value: result[1].children()[0].val() },
        third: { team: result[2].id, value: result[2].children()[0].val() },
        fourth: { team: result[3].id, value: result[3].children()[0].val() },
        fifth: { team: result[4].id, value: result[4].children()[0].val() },
        sixth: { team: result[5].id, value: result[5].children()[0].val() },
        seventh: { team: result[6].id, value: result[6].children()[0].val() }
        };

        alert(attributes.first.team + attributes.first.value);
    }
});

推荐答案

$("#sortlist").sortable("toArray")返回可排序项目ID的数组,该ID是字符串的数组.

$("#sortlist").sortable("toArray") returns an array of sortable items' ids, which is an array of strings.

字符串没有id属性和children方法.

A string don't have id property and children method.

这篇关于jQuery:为什么不触发警报?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆