gpt4 book ai didi

javascript - 未捕获的 ReferenceError : onPrevious is not defined at HTMLAnchorElement. onclick

转载 作者:行者123 更新时间:2023-11-28 00:44:45 25 4
gpt4 key购买 nike

我有 Uncaught ReferenceError: previous is not defined at HTMLAnchorElement.onclick 请帮助我,我已经尝试过之前针对同一问题提供的所有解决方案,但没有帮助。我也已经有了 jquery 版本和 bootstrap 版本。我正在粘贴整个脚本代码和放置按钮的 html 标记。

<ul class="pager wizard">
<li class="previous"><a href="javascript:;" >Previous</a></li>
<li class="next"><a href="javascript: void(0);" onclick="onPrevious(tab, navigation, index);">Next</a></li>
</ul>


<script>
$(document).ready(function() {
// You don't need to care about this function
// It is for the specific demo
function adjustIframeHeight() {
var $body = $('body'),
$iframe = $body.data('iframe.fv');
if ($iframe) {
// Adjust the height of iframe
$iframe.height($body.height());
}
}

$('#installationForm')
.formValidation({
framework: 'bootstrap',
icon: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
// This option will not ignore invisible fields which belong to inactive panels
excluded: ':disabled',
fields: {
type_of_service: {
validators: {
notEmpty: {
message: 'The type of service is required'
}
}
},
academic_level: {
validators: {
notEmpty: {
message: 'The academic level is required'
}
}
},

type_of_paper: {
validators: {
notEmpty: {
message: 'The type of paper is required'
}
}
},

topic: {
validators: {
notEmpty: {
message: 'The topic is required'
}
}
},

subject: {
validators: {
notEmpty: {
message: 'The subject is required'
}
}
},

type_of_citation: {
validators: {
notEmpty: {
message: 'The type of citation is required'
}
}
},

order_deadline: {
validators: {
notEmpty: {
message: 'The order deadline is required'
}
}
},
pages: {
validators: {
notEmpty: {
message: 'The number of pages is required'
}
}
},
type_of_spacing: {
validators: {
notEmpty: {
message: 'The type of spacing is required'
}
}
},

category_of_writer: {
validators: {
notEmpty: {
message: 'Select your prefered writer'
}
}
},

fullname: {
validators: {
notEmpty: {
message: 'Please specify your full name'
}
}
},

email: {
validators: {
notEmpty: {
message: 'The email address is required'
},
emailAddress: {
message: 'The email address is not valid'
}
}
},
dbServer: {
validators: {
notEmpty: {
message: 'The server IP is required'
},
ip: {
message: 'The server IP is not valid'
}
}
},
dbName: {
validators: {
notEmpty: {
message: 'The database name is required'
}
}
},
dbUser: {
validators: {
notEmpty: {
message: 'The database user is required'
}
}
}
}
})
.bootstrapWizard({
tabClass: 'nav nav-pills',
onTabClick: function(tab, navigation, index) {
return validateTab(index);
},
onNext: function(tab, navigation, index) {
var numTabs = $('#installationForm').find('.tab-pane').length,
isValidTab = validateTab(index - 1);
if (!isValidTab) {
return false;
}

if (index === numTabs) {
// We are at the last tab

// Uncomment the following line to submit the form using the defaultSubmit() method
$('#installationForm').formValidation('defaultSubmit');

// For testing purpose
//$('#completeModal').modal();
}

return true;
},
onPrevious: function(tab, navigation, index) {
return validateTab(index + 1);
},
onTabShow: function(tab, navigation, index) {
// Update the label of Next button when we are at the last tab
var numTabs = $('#installationForm').find('.tab-pane').length;
$('#installationForm')
.find('.next')
.removeClass('disabled') // Enable the Next button
.find('a')
.html(index === numTabs - 1 ? 'Place Order' : 'Next');

// You don't need to care about it
// It is for the specific demo
adjustIframeHeight();
}
});
function validateTab(index) {
var fv = $('#installationForm').data('formValidation'), // FormValidation instance
// The current tab
$tab = $('#installationForm').find('.tab-pane').eq(index);

// Validate the container
fv.validateContainer($tab);
var isValidStep = fv.isValidContainer($tab);
if (isValidStep === false || isValidStep === null) {
// Do not jump to the target tab
return false;
}
return true;`enter code here`
}

});`enter code here`
</script>

最佳答案

一个简单的解决方案可能是在全局范围内声明它并在 jQuery 范围内重用它。

<ul class="pager wizard">
<li class="previous"><a href="javascript:;" >Previous</a></li>
<li class="next"><a href="javascript: void(0);" onclick="onPrevious(tab, navigation, index);">Next</a></li>
</ul>


<script>

// Your function is declared globally.
function onPrevious(tab, navigation, index) {
return validateTab(index + 1);
}

$(document).ready(function() {
// You don't need to care about this function
// It is for the specific demo
function adjustIframeHeight() {
var $body = $('body'),
$iframe = $body.data('iframe.fv');
if ($iframe) {
// Adjust the height of iframe
$iframe.height($body.height());
}
}

$('#installationForm')
.formValidation({
framework: 'bootstrap',
icon: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
// This option will not ignore invisible fields which belong to inactive panels
excluded: ':disabled',
fields: {
type_of_service: {
validators: {
notEmpty: {
message: 'The type of service is required'
}
}
},
academic_level: {
validators: {
notEmpty: {
message: 'The academic level is required'
}
}
},

type_of_paper: {
validators: {
notEmpty: {
message: 'The type of paper is required'
}
}
},

topic: {
validators: {
notEmpty: {
message: 'The topic is required'
}
}
},

subject: {
validators: {
notEmpty: {
message: 'The subject is required'
}
}
},

type_of_citation: {
validators: {
notEmpty: {
message: 'The type of citation is required'
}
}
},

order_deadline: {
validators: {
notEmpty: {
message: 'The order deadline is required'
}
}
},
pages: {
validators: {
notEmpty: {
message: 'The number of pages is required'
}
}
},
type_of_spacing: {
validators: {
notEmpty: {
message: 'The type of spacing is required'
}
}
},

category_of_writer: {
validators: {
notEmpty: {
message: 'Select your prefered writer'
}
}
},

fullname: {
validators: {
notEmpty: {
message: 'Please specify your full name'
}
}
},

email: {
validators: {
notEmpty: {
message: 'The email address is required'
},
emailAddress: {
message: 'The email address is not valid'
}
}
},
dbServer: {
validators: {
notEmpty: {
message: 'The server IP is required'
},
ip: {
message: 'The server IP is not valid'
}
}
},
dbName: {
validators: {
notEmpty: {
message: 'The database name is required'
}
}
},
dbUser: {
validators: {
notEmpty: {
message: 'The database user is required'
}
}
}
}
})
.bootstrapWizard({
tabClass: 'nav nav-pills',
onTabClick: function(tab, navigation, index) {
return validateTab(index);
},
onNext: function(tab, navigation, index) {
var numTabs = $('#installationForm').find('.tab-pane').length,
isValidTab = validateTab(index - 1);
if (!isValidTab) {
return false;
}

if (index === numTabs) {
// We are at the last tab

// Uncomment the following line to submit the form using the defaultSubmit() method
$('#installationForm').formValidation('defaultSubmit');

// For testing purpose
//$('#completeModal').modal();
}

return true;
},
onPrevious: onPrevious, // You reuse it here.
onTabShow: function(tab, navigation, index) {
// Update the label of Next button when we are at the last tab
var numTabs = $('#installationForm').find('.tab-pane').length;
$('#installationForm')
.find('.next')
.removeClass('disabled') // Enable the Next button
.find('a')
.html(index === numTabs - 1 ? 'Place Order' : 'Next');

// You don't need to care about it
// It is for the specific demo
adjustIframeHeight();
}
});
function validateTab(index) {
var fv = $('#installationForm').data('formValidation'), // FormValidation instance
// The current tab
$tab = $('#installationForm').find('.tab-pane').eq(index);

// Validate the container
fv.validateContainer($tab);
var isValidStep = fv.isValidContainer($tab);
if (isValidStep === false || isValidStep === null) {
// Do not jump to the target tab
return false;
}
return true;
}

});
</script>

编辑

这里有一个片段可以证明它是有效的。

<ul class="pager wizard">
<li class="previous"><a href="javascript:;" >Previous</a></li>
<li class="next"><a href="javascript: void(0);" onclick="onPrevious('tab', 'navigation', 'index');">Next</a></li>
</ul>

<script>
// Your function is declared globally.
function onPrevious(tab, navigation, index) {
console.log(tab, navigation, index)
//return validateTab(index + 1);
}
</script>

关于javascript - 未捕获的 ReferenceError : onPrevious is not defined at HTMLAnchorElement. onclick,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51304674/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com