简体   繁体   English

Javascript代码正确,但在Microsoft Visual Studio中不起作用

[英]Javascript code is right but not work in Microsoft Visual studio

simple coding in javascript using Microsoft Visual Studio Enterprise 2017 in a VM. 在VM中使用Microsoft Visual Studio Enterprise 2017在javascript中进行简单编码。

The user I am helping is using Microsoft Visual Studio Enterprise 2017 in a VM. 我正在帮助的用户正在VM中使用Microsoft Visual Studio Enterprise 2017。 Simple development using javascript and html. 使用javascript和html进行简单开发。

The code is right - I have taken the code, created a project in a localized version of Visual Studio Community 2019 and it works. 该代码是正确的-我已经接受了代码,在Visual Studio Community 2019的本地化版本中创建了一个项目,并且可以正常工作。 Another user has the same code inside a separate VM identical to my user and it works. 另一个用户在与我的用户相同的单独VM中具有相同的代码,并且可以正常工作。

The code in question is a switch statement. 有问题的代码是switch语句。 The buttons in the table when pressed calls the switch statement but none of the cases are met. 按下表中的按钮会调用switch语句,但不会满足任何情况。 We know this because we put an alert at the switch and the alert popped up, but when we put alerts in the case statement, it didn't appear (not to mention the buttons didn't work). 我们之所以知道这一点,是因为我们在开关上放置了一个警报,并且弹出了警报,但是当我们在case语句中放置警报时,它没有出现(更不用说按钮不起作用了)。 Again,full functionality using the same code (all inside index.cshtml) on two other versions. 同样,在其他两个版本上使用相同的代码(全部包含在index.cshtml中)具有全部功能。

We also know the refresh function is working - so the script there is no question the script code is being read. 我们也知道刷新功能正在工作-因此脚本毫无疑问正在读取脚本代码。

So we know this code works in two separate versions of Microsoft Visual studio, one inside a VM like my user and one in a standalone local version. 因此,我们知道此代码可在Microsoft Visual Studio的两个不同版本中工作,一个在类似于我的用户的VM内,另一个在独立的本地版本中。

We've tried F12 and we get some statement about a carat that apparently is a recurring problems. 我们已经尝试过F12,并且得到一些有关克拉的陈述,这显然是经常性的问题。 Since its an enterprise version inside a VM I am reluctant to ask the user to do anything radical like devenv /resetuserdata 由于它是VM中的企业版,因此​​我不愿意要求用户执行诸如devenv / resetuserdata之类的根本性操作

So this really isn't a coding issue, but I'm at a loss to troubleshoot because of a success of building the projects in other Visual Studio installations. 因此,这实际上不是编码问题,但是由于成功在其他Visual Studio安装中构建了项目,因此我无所适从。 Let me add- this isn't copying a solution from one environment to the other, its building individual projects and using the same code. 我要补充一点-这不是将解决方案从一个环境复制到另一个环境,而是构建单个项目并使用相同的代码。

<script>
function RefreshPage() {
        window.location.reload(true);
    }
    function ClearFields(field) {
        switch (field) {
            case 'I':
                $("#txtItemNumber").val("");
                break;
            case 'A':
                $("#txtItemNumber, #txtCategoryNumber").val("");
                break;
            case 'C':
                $("#txtCategoryNumber").val("");
                break;
        }
    }
</script>

 <td>
            <input placeholder="ItemNumber" type="text" id="txtItemNumber"
                   style="font-size:large;text-align: center; height: 44px;" />
        </td>
        <td style="padding-left:20px;">
            <div>
                <button onclick="RefreshPage(); return false;" type="button" class="btn btn-info btn-sm"><span class="glyphicon glyphicon-refresh"></span>Refresh</button>
            </div>
        </td>
        <td style="padding-left: 20px;">
            <div>
                <button onclick="ClearFields('I'); return false;" type="button" class="btn btn-info btn-xs"><span class="glyphicon glyphicon-clear"></span>Clear</button>
            </div>
        </td>
        <td style="padding-left: 20px;">
            <div>
                <button onclick="ClearFields('A'); return false;" type="button" class="btn btn-info btn-xs"><span class="glyphicon glyphicon-clear"></span>ClearAll</button>
            </div>
        </td>
    </tr>
    <tr>
        <td>
            <label style="font-size:large;">
                Enter Category Number:&nbsp;
            </label>
        </td>
        <td>
            <input placeholder="Category Number" type="text" id="txtCategoryNumber"
                   style="font-size:large; text-align: center; height: 44px;" />
        </td>
        <td style="padding-left: 22px;">
            <div>
                <button onclick="ClearFields('C'); return false;" type="button" class="btn btn-info btn-xs"><span class="glyphicon glyphicon=clear"></span> Clear</button>
            </div>
        </td>
    </tr>

After some internet sluething I focused on the Jquery not working. 经过一番互联网讨价还价之后,我专注于Jquery无法正常工作。

In this case I was able to solve the problem by adding a new script statement that pointed to 在这种情况下,我可以通过添加指向以下内容的新脚本语句来解决该问题

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

then we found the offending code. 然后我们找到了令人反感的代码。 Even though it was sourcing jquery-3.2.1.min.js, there was another reference in the _layoutPage.cshtml file that included this line 即使它正在采购jquery-3.2.1.min.js,但_layoutPage.cshtml文件中还有另一引用包含此行

    <script type="text/javascript" src="@Url.Content("~/Scripts/JQuery/jquery-1.11.3.min.js")"></script>

which was overriding. 这是压倒一切的。 This piece of code resulted in jQuery not working and would not have worked until we addressed the multiple jQuery.xxx.js files being referenced throughout the project. 这段代码导致jQuery无法正常工作,并且直到我们解决了整个项目中引用的多个jQuery.xxx.js文件时,它才起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM