Home > Backend Development > PHP Tutorial > jquery 让radio 选中

jquery 让radio 选中

WBOY
Release: 2016-06-06 20:43:40
Original
1091 people have browsed it

script.js

<code>$("input:radio[name=pdiyong]").click(function(){


pay_sum = parseFloat($("#pay-sum").text());

if($("input:radio[name=pdiyong]:checked").data('par') > 0)
{
    if( pay_sum > 30)
    {
        $("input:radio[name=prop]").attr('disabled','disabled');
    }
    else
    {
        $("input:radio[name='pdiyong'][data-par='0']").attr("checked",true);
        $("input:radio[name='pdiyong']").attr('disabled','disabled');
        alert("实付未超过30元,不能使用抵用券!")
    }
}
else
{

    $("input:radio[name=prop]").removeAttr('disabled');
}

})
</code>
Copy after login
Copy after login

index.php

<code><present name="pdiyong">
<div class="quan-list">
<h3>抵用券<i>(需实付金额超过¥30元,方可使用。每次5元累计使用)</i>
</h3>
<ul class="diyong">
<li>
<input type="radio" name="pdiyong" data-par="0" value="0" checked>不使用抵用券</li>
<volist name="pdiyong" id="item">
<li>
<input type="radio" name="pdiyong" data-par="{$item.value}" value="{$item.id}">名称:{$item.name} 金额:{$item.value}</li>
</volist>
</ul>
</div>
</present>
<present name="prop">
<div class="quan-list">
<h3>代金券<i>(需实付金额超过¥10元,方可使用。不累计使用)</i>
</h3>
<ul class="prop">
    <li>
<input type="radio" name="prop" data-par="0" value="0" checked>不使用代金券</li>
<volist name="prop" id="item">
    <li>
<input type="radio" name="prop" data-par="{$item.value}" value="{$item.id}"> 名称:{$item.name} 金额:{$item.value}</li>
</volist>
</ul>
</div>
</present>
</code>
Copy after login
Copy after login

没办法让value='0'的选中,是怎么回事呢?

回复内容:

script.js

<code>$("input:radio[name=pdiyong]").click(function(){


pay_sum = parseFloat($("#pay-sum").text());

if($("input:radio[name=pdiyong]:checked").data('par') > 0)
{
    if( pay_sum > 30)
    {
        $("input:radio[name=prop]").attr('disabled','disabled');
    }
    else
    {
        $("input:radio[name='pdiyong'][data-par='0']").attr("checked",true);
        $("input:radio[name='pdiyong']").attr('disabled','disabled');
        alert("实付未超过30元,不能使用抵用券!")
    }
}
else
{

    $("input:radio[name=prop]").removeAttr('disabled');
}

})
</code>
Copy after login
Copy after login

index.php

<code><present name="pdiyong">
<div class="quan-list">
<h3>抵用券<i>(需实付金额超过¥30元,方可使用。每次5元累计使用)</i>
</h3>
<ul class="diyong">
<li>
<input type="radio" name="pdiyong" data-par="0" value="0" checked>不使用抵用券</li>
<volist name="pdiyong" id="item">
<li>
<input type="radio" name="pdiyong" data-par="{$item.value}" value="{$item.id}">名称:{$item.name} 金额:{$item.value}</li>
</volist>
</ul>
</div>
</present>
<present name="prop">
<div class="quan-list">
<h3>代金券<i>(需实付金额超过¥10元,方可使用。不累计使用)</i>
</h3>
<ul class="prop">
    <li>
<input type="radio" name="prop" data-par="0" value="0" checked>不使用代金券</li>
<volist name="prop" id="item">
    <li>
<input type="radio" name="prop" data-par="{$item.value}" value="{$item.id}"> 名称:{$item.name} 金额:{$item.value}</li>
</volist>
</ul>
</div>
</present>
</code>
Copy after login
Copy after login

没办法让value='0'的选中,是怎么回事呢?

$("input:radio[name='pdiyong'][data-par='0']").attr("checked",true);
用prop()方法,关于prop和attr方法区别,自行google

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template