簡體   English   中英

單選按鈕未獲取html中選中的值

[英]radio button not getting a value of checked in html

嗨,大家好,希望有人能幫助我。,目前我在做有關Javasipting的研究,這件事讓我頭疼。 下面是我的代碼:html

<div class="row">
<div class="col-sm-10 col-sm-offset-1">
    <h6 class="info-text text-danger"> {{ $errors->first('register_scanning') }} </h6>
    <div class="col-sm-3">
        <div class="choice" data-toggle="radio_scanning" id="radio_scanning_0">
            {{ Form::radio('register_scanning', '0800-1200') }}
            <div class="icon">
                <i class="fa fa-pencil"></i>
            </div>
            <h7>Live Scanning 0800-1200</h7>
        </div>
    </div>
    <div class="col-sm-3">
        <div class="choice" data-toggle="radio_scanning" id="radio_scanning_1">
            {{ Form::radio('register_scanning', '1300-1700') }}
            <div class="icon">
                <i class="fa fa-terminal"></i>
            </div>
            <h7>Live Scanning 1300-1700</h7>
        </div>

    </div>
</div>

好的,所以這是html,當然還有一些laravel刀片代碼。 這是JavaScript:

$('[data-toggle="radio_scanning"]').click(function(event){
    wizard = $(this).closest('.wizard-card');
    wizard.find('[data-toggle="radio_scanning"]').removeClass('active');
    $(this).addClass('active');
    $(wizard).find('[name="register_scanning"]').removeAttr('checked');
    $(this).find('[name="register_scanning"]').attr('checked','true');
});

$('[data-toggle="radio_cadaver"]').click(function(event){
    wizard = $(this).closest('.wizard-card');
    wizard.find('[data-toggle="radio_cadaver"]').removeClass('active');
    $(this).addClass('active');
    $(wizard).find('[name="register_cadaver"]').removeAttr('checked');
    $(this).find('[name="register_cadaver"]').attr('checked','true');
});

$('#radio_scanning_0').click(function () {
    $("#radio_cadaver_0").hide('fast');
    $("#radio_cadaver_1").hide('fast');

    $("#radio_cadaver_2").show('fast');
    $("#radio_cadaver_3").show('fast');
});
$('#radio_scanning_1').click(function () {
    $("#radio_cadaver_0").show('fast');
    $("#radio_cadaver_1").show('fast');

    $("#radio_cadaver_2").hide('fast');
    $("#radio_cadaver_3").hide('fast');
 });

這是放置在文檔中的。現在准備進行解釋:該腳本是選擇單選按鈕並為其賦予check值,因為我已經創建了單選按鈕,如下所示 單選按鈕

因此,我能夠單擊單選按鈕並突出顯示它們,但是當我提交表單時,它將返回一個錯誤,提示我需要從單選按鈕中選擇一個選項。這意味着未選中單選按鈕。當我在Firefox上時發生。 事實是,它僅在Firefox和IE中可以在chrome和Opera中正常運行。 我做錯了嗎? javascript我的意思是,我做錯了還是錯過了什么?

感謝您花費寶貴的時間和精力來關注我的問題。

在表單標簽中添加autocomplete="off"應該可以解決此問題。 還是我聽說過。 我從來沒有嘗試過。

只需在以下行上更改一個簡單值:

 $(this).find('[name="register_scanning"]').**prop**('checked','true');  *// Good!*

代替:

 $(this).find('[name="register_scanning"]').**attr**('checked','true');  *//Wrong*

就這樣!

我希望它會有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM