本文介绍了Popup Alert .....有人可以帮助我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在这张图片中有一个输出
http://farm8.staticflickr.com/7314/11269674244_6ddf5a65cf.jpg



问题是我如何连接按钮same和文本same1中的文本total



1:script

  function myFunction(){

var total = 0;
$(input(type ='checkbox')。each(function(index){
if($(this).is(':checked')){

//这是复选框!

//将总数加到

// Value是一个字符串,所以需要将其转换为整数(Numeric)
total + = parseInt($(this).attr(value));
}
});
//显示最终总值
$(#total)。val(total);



:html

 <形式> 

< input name =100type =checkboxid =bikevalue =100>< label for =bike> 100< / label>< BR>
< input type =checkboxid =bike2value =100>< label for =bike2> 100< / label>< br>
< input type =checkboxid =bike3value =100>< label for =bike3> 100< / label>< br>
< input type =checkboxid =bike4value =100>< label for =bike4> 100< / label>< br>
< input type =checkboxid =bike5value =100>< label for =bike5> 100< / label>< br>
< input type =checkboxid =bike6value =100>< label for =bike6> 100< / label>< br>
< input type =checkboxid =bike7value =100>< label for =bike7> 100< / label>< br>
< input type =checkboxid =bike8value =100>< label for =bike8> 100< / label>< br>
< input type =checkboxid =bike9value =100>< label for =bike9> 100< / label>< br>
< input type =checkboxid =bike1value =100>< label for =bike1> 100< / label>< br>
< button type =buttononclick =myFunction()>等于< /按钮>
< input onclick =myFunction()type =textid =totalvalue =0>< br>
< button type =buttononclick =>相同< / button>
< input onclick =type =textid =same1value =0>
< / form>


解决方案

我在jsfiddle中有一个演示。



 (function($){
$(document).ready(function(){
$('form')。on('点击',功能(e){
switch(e.target.id){
case'btnEqual':
setTotal(getTotal());
break;
'btnSame':
showMsg();
break;
default:break;
}
});
});

函数getTotal(){

var total = 0;
$(input [type ='checkbox')。each(function(index){
if($(this).is(':checked')){
//这是复选框!
//将总额加到
// Value是所以,你需要将它转换为整数(数值)
total + = parseInt($(this).attr(value),10);
}
});

总回报;
};

function setTotal(total){
$(#total)。val(total);
};

function getSame(){
return parseInt($('#same1')。val(),10);
};

function showMsg(){

var sameVal = getSame(),selectedTotal = getTotal();

if(sameVal> = selectedTotal){

console.log('Good');

} else {

console.log('Wrong');

}
};

})(jQuery);

有用或想要吗?

i want to have an output like in this picturehttp://farm8.staticflickr.com/7314/11269674244_6ddf5a65cf.jpg

the question is how can i connect text"total" in button "same" and text"same1"

1:script

function myFunction(){

    var total = 0;
    $("input[type='checkbox'").each(function (index) {
        if ($(this).is(':checked')) {

            // This is checked checkbox !

            // Add the amount to total

            // Value is a string. So, you need to convert it integer (Numeric)
            total += parseInt($(this).attr("value"));
        }
    });
    // Show the final total value
    $("#total").val(total);
}

2:html

<form>

    <input name="100" type="checkbox" id="bike" value="100"><label for="bike">100</label><br>
    <input type="checkbox" id="bike2" value="100"><label for="bike2">100</label><br>
    <input type="checkbox" id="bike3" value="100"><label for="bike3">100</label><br>
    <input type="checkbox" id="bike4" value="100"><label for="bike4">100</label><br>
    <input type="checkbox" id="bike5" value="100"><label for="bike5">100</label><br>
    <input type="checkbox" id="bike6" value="100"><label for="bike6">100</label><br>
    <input type="checkbox" id="bike7" value="100"><label for="bike7">100</label><br>
    <input type="checkbox" id="bike8" value="100"><label for="bike8">100</label><br>
    <input type="checkbox" id="bike9" value="100"><label for="bike9">100</label><br>
    <input type="checkbox" id="bike1" value="100"><label for="bike1">100</label><br>
    <button type="button" onclick="myFunction()">Equal</button>
    <input onclick="myFunction()" type="text" id="total" value="0"><br>
    <button type="button" onclick="">Same</button>
    <input onclick="" type="text" id="same1" value="0">
</form>
解决方案

I have a demo in jsfiddle.

Demo Here

    (function($){
    $(document).ready(function(){
        $('form').on('click',function(e){
            switch(e.target.id){
                case 'btnEqual':
                    setTotal(getTotal());
                    break;
                case 'btnSame':
                    showMsg();
                    break;
                default:break;
            }
        });
    });

    function getTotal(){

        var total = 0;
        $("input[type='checkbox'").each(function (index) {
            if ($(this).is(':checked')) {
                // This is checked checkbox !
                // Add the amount to total
                // Value is a string. So, you need to convert it integer (Numeric)
                total += parseInt($(this).attr("value"),10);
            }
        });

        return total;
    };

    function setTotal(total){
        $("#total").val(total);
    };

    function getSame(){
        return parseInt($('#same1').val(),10);
    };

    function showMsg(){

        var sameVal=getSame(),selectedTotal=getTotal();

        if(sameVal>=selectedTotal){

            console.log('Good');

        }else{

            console.log('Wrong');

        }
    };

})(jQuery);

It's helpful or you want ?

这篇关于Popup Alert .....有人可以帮助我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 13:08