无法正常工作,请移动到另一页

Does not work properly move to another page

本文关键字:移动 一页 工作 常工作      更新时间:2023-09-26

我有4个按钮。

其中三人正在出示执照。其中一个标题为"企业"的页面必须转到另一个页面。

不幸的是,当我点击"企业"时,会显示许可证,然后页面转到另一个页面。

我如何做到不传递代码来显示许可证,而是立即传递到另一个页面?

我的代码:

$('input[title="enterprise"]').click(function(){
    window.location.href = "/contact";
});
$('input[type=button]').click(showLicence).each(function() {
    this.version = this.title;
    this.title = "Buy ";
    switch(this.version) {
        case 'basic':
            this.title += 'Basic';
            break;
        case 'standard':
            this.title += 'Standard';
            break;
        case 'business':
            this.title += 'Business';
            break;
    }
});

尝试使用:not

$('input[type=button]:not([title="enterprise"])').click(showLicence).each(function() {

更改第二个事件处理程序,以便排除enterprise按钮:

$('input[type=button]:not([title="enterprise"])').click(showLicence).each(function() {

添加一个唯一的类来分隔这两个功能。

例如:

<button class="enterprise">Enterprise</button>
<button class="normal">Basic</button>
<button class="normal">Standard</button>
<button class="normal">Business</button>

然后在JS中做一个细微的更改:

$('.enterprise').click(function(){
    window.location.href = "/contact";
});
$('.normal').click(showLicence).each(function() {
    this.version = this.title;
    this.title = "Buy ";
    switch(this.version) {
        case 'basic':
            this.title += 'Basic';
            break;
        case 'standard':
            this.title += 'Standard';
            break;
        case 'business':
            this.title += 'Business';
            break;
    }
});

您可以根据需要将所有属性添加到按钮中。希望这是有道理的。

也许您可以使用"default"switch关键字(或添加"Enterprise"案例):

$('input[type=button]').click(showLicence).each(function() {
this.version = this.title;
this.title = "Buy ";
switch(this.version) {
    case 'basic':
        this.title += 'Basic';
        break;
    case 'standard':
        this.title += 'Standard';
        break;
    case 'business':
        this.title += 'Business';
        break;
    default:
        window.location.href = "/contact";
}

});