小编Mar*_*ill的帖子

单选按钮未正确验证

我有这个问卷,我用来开始一个应用程序.我在提交之前使用javascript进行验证,但我遇到的问题是,它只验证每个问题上的第二个按钮,而不是单独验证每个问题.我在下面发布了代码.

调查问卷

<?
    for($i = 1; $i <= count($questions); $i++){
        print "<div class='form-group'>";
            print "<div class='col-md-12'>";
                print "<p>$i) ".$questions[$i-1]."</p>";
                print "<label class='radio-inline'>";
                    print "<input type='radio' name='q$i' value='1'>Yes";
                print "</label>";
                print "<label class='radio-inline'>";
                    print "<input type='radio' name='q$i' value='-1'>No";
                print "</label>";
            print "</div>";
        print "</div>";
    }
?>
Run Code Online (Sandbox Code Playgroud)

使用Javascript

$(function(){
    $('#questionaire-form').submit(function(e){
        e.preventDefault();
        var prevname = "";
        var questions = [];
        $('.radio-inline').each(function(){
            //$(this).next($(this)).is(':checked'));            
            var curname = $(this).find('input[type="radio"]').attr('name');
            if(prevname == curname){
                if(!$(this).find('input[name='+curname+']').is(':checked') && $(this).closest('div').find('p').hasClass('text-danger')){
                    return true; //skip to the next element
                }else if(!$(this).find('input[name='+curname+']').is(':checked') && !$(this).closest('div').find('p').hasClass('text-danger')){ …
Run Code Online (Sandbox Code Playgroud)

javascript validation jquery

7
推荐指数
1
解决办法
107
查看次数

将输入默认为一种文本?

所以我有一个相当随意的问题但是我们走了.我正在使用Javascript为插件制作一些技巧.假设我有一个看起来像这样的输入:

<input type='cc' id='cc' class='' />
Run Code Online (Sandbox Code Playgroud)

显然,类型cc不是有效的输入类型.html是否会自动默认未知类型text,还是会产生不利影响?

html javascript

7
推荐指数
1
解决办法
1201
查看次数

我如何在TemplateRef中找到Element

我一直在搜寻,但是对角度5/6还是有点陌生​​,但是我正在尝试看看是否有可能。


问题

说我有一个模板:

<ng-template #rt let-r="result" let-t="term">
  <ngb-highlight [result]="r.typeAheadDisplayName" [term]="t" ></ngb-highlight>
  <span *ngIf="r.primaryName ">(alias for {{ r.primaryName }}) </span>{{ r.metaData }}
</ng-template>
Run Code Online (Sandbox Code Playgroud)

在此模板内,将生成一个按钮,可用作选择选项的一种方法。但是,由于给定的原因,我需要能够定位:first-child按钮数组。

我知道我可以选择要执行的元素/模板:

@ViewChild('rt') rt : TemplateRef<any>;
Run Code Online (Sandbox Code Playgroud)

但是,实际上我是否可以执行类似于jQuery的功能,.find甚至可以在AngularJS中执行相同的功能,以定位将在此模板内找到的元素。我一直在谷歌搜索,看不到找到答案。

angular

6
推荐指数
1
解决办法
4883
查看次数

具有localhost:3000的http服务器给出ERR_INVALID_REDIRECT

我已经使用以下命令安装了http-server:

npm i -g http-server

运行服务器后,我得到响应说 Running on 127.0.0.1:8080

我的电话看起来像这样:

http-server -a 0.0.0.0 -c-1

如果我去127.0.0.1:808010.1.1.72:8080得到:

This page is not working.

127.0.0.1:8080 sent an invalid response

ERR_INVALID_REDIRECT

我到处搜索和搜索,实际上没有什么答案。我不使用XAMPP或IIS只是一个空白节点服务器。

Node.js: 11.12.0

npm: 6.7.0

OS: Windows 10

我已经检查了我的主机文件。那里没有相关的东西。我不知道是什么原因造成的。我也不使用.htaccess文件或Web.config文件。

如果您需要更多信息,请告诉我。

笔记

如果我去,localhost:8080/index.html我可以去我的应用程序。虽然这不应该那样工作。

windows node.js

6
推荐指数
3
解决办法
3264
查看次数

标签 统计

javascript ×2

angular ×1

html ×1

jquery ×1

node.js ×1

validation ×1

windows ×1