我仍然在学习技巧,并且在控制台中得到了这个错误。
您可以找到指向测试页面[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);部分的这个错误。
发布于 2017-05-12 00:16:40
对于我在这里看到的,您的jquery.noConflict();它没有以正确的方式关闭,请尝试遵循以下代码:
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);
https://stackoverflow.com/questions/43920692
复制相似问题