【发布时间】:2017-10-10 18:25:37
【问题描述】:
我仍在学习中,我在控制台中遇到了这个错误。
你可以找到测试页面的链接[here][1]
missing ) after argument list
对于这个 jQuery 代码:
jQuery.noConflict();
(function ($) {
function readyFn() {
$.fn.extend({
Segment: function ( ) {
$(this).each(function (){
var self = $(this);
var onchange = self.attr('onchange');
var wrapper = $("<div>",{class: "ui-segment"});
$(this).find("option").each(function (){
var option = $("<span>",{class: 'option',onclick:onchange,text: $(this).text(),value: $(this).val()});
if ($(this).is(":selected")){
option.addClass("active");
}
wrapper.append(option);
});
wrapper.find("span.option").click(function (){
wrapper.find("span.option").removeClass("active");
$(this).addClass("active");
self.val($(this).attr('value'));
});
$(this).after(wrapper);
$(this).hide();
});
}
});
$(".segment-select").Segment();
var options = {
monthly: [
{price: 25, link: 'link1'},
{price: 45, link: 'link2'},
{price: 145, link: 'link3'},
],
yearly: [
{price: 300, link: 'link4'},
{price: 540, link: 'link5'},
{price: 640, link: 'link6'},
]
}
function fillContent(interval) {
var data = options[interval];
$('.content').each(function(index) {
var content = $(this);
content.find('span.price').text('$' + data[index]span.price);
content.find('span.interval').text(interval);
content.find('span.link').attr('href', data[index]span.link);
});
}
// initialization
fillContent("monthly");
$('.ui-segment').on("click", '.option', function() {
var interval = $(this).attr('value');
fillContent(interval);
});
}
$(document).ready(readyFn);
})(jQuery);
会有什么问题?我确实在指向代码的content.find('span.price').text('$' + data[index]span.price); 部分的控制台中看到了这个错误。
【问题讨论】:
-
span应该在data[index]span.price中是什么?不应该只是data[index].price吗? -
好吧,你可能会说。我把它改回
.price,但这没有用。另外,当我检查元素时,它会显示span.price。如果我错了,请纠正我。 -
DOM 元素与您尝试访问的对象没有任何关系。
-
明白。好吧,尝试了不同的价格变化。在页脚中加载脚本也不起作用。有什么建议吗?