2015-04-23 25 views
0

我正在支付網關中工作,其中用戶爲我的數字圖書命名價格。顯示一個輸入框(用於顯示價格)和一個「立即付款」按鈕。但是:如果輸入爲0或默認情況下顯示/隱藏div

  1. 如果價格低於0.50付款按鈕disapear和下載按鈕出現
  2. 如果用戶引入「」代替「」顯示一個對話框(請輸入有效的數字)

這裏是輸入框的形式:

<form id="hikashop_paypal_form" name="hikashop_paypal_form" action="https://www.paypal.com/cgi-bin/webscr" method="post"> 

    <input type="hidden" name="cmd" value="_cart"> 
    <input type="hidden" name="business" value="X" /> 
    <input type="hidden" name="item_name_1" value="X" /> 
    <input id="amount_1" name="amount_1" class="amount_1"/></form> 

立即付款按鈕(它應該如果1是真的被隱伏)

<div id="PayNow" class="PayNow"> 
    <input id="PayNow_button" type="submit" class="btn btn-primary" value="Pay now" name="" /> 
    </div> 

立即下載按鈕(應該顯示,如果1爲真)

<div id="downloadNow" class="downloadNow"> 
    <a href="www.download.com"/download">Download now</a> 
    </div> 

信息框(應顯示爲2是否爲真)

<div id="info" class="info"> 
    Enter a valid number 
    </div> 

問題是:我該怎麼做? 我supose解決方案經過使用JavaScript,但我不知道究竟怎麼了...感謝您的時間...

+2

你使用任何框架或只是簡單的JS + HTML? –

+0

向我們展示您的代碼! – Vikrant

+0

這是我的測試頁面的鏈接:[test](http://www.bernatmoreno.com/mensajes/testeando) –

回答

0

我不知道怎麼回事,但我的作品:

嘗試在這裏:IBIZA! Book Download

<form id="pplaunch" action="https://www.paypal.com/cgi-bin/webscr" method="POST"> 
      <input type="hidden" name="cmd" value="_xclick"> 
    <input id="issueid" name="issueid" type="hidden" value="ARCHIVE NAME"> 
    <input type="hidden" id="currency" name="currency" value="EUR"> 
    <input type="hidden" name="business" value="YOUR PAYPAL ID" /> 
    <input type="hidden" value="0" name="test_ipn"></input> 
    <input type="hidden" name="item_name" value="PRODUC NAME"> 
    <input type="hidden" value="1" name="no_shipping"></input> 
    <input type="hidden" value="0" name="no_note"></input> 
    <input type="hidden" value="utf-8" name="charset"></input> 
    <input type="hidden" value="Super" name="first_name"></input> 
    <input type="hidden" value="http://www.YOURWEBSITE.com/return" name="return"></input> 
    <input type="hidden" value="http://www.OURWEBSITE.com/cancel" name="cancel_return"></input> 
    <div class="nameprice" style="float:left;margin-right:15px;> 
     <span style="font-size:small;">Name your price: </span><input id="amount" name="amount" size="6" maxlength="5" type="text"> <span style="font-size:small;color:#ccc;">From 0.00€</span> 
    </div> 
    <div id="pricerror"></div> 
    <div class="buttonspace"> 
     <button id="buybutton" class="buybutton" type="button">Checkout</button> 
        <div id="descargaGratisMensaje"></div> 
     <div style="display: block;" class="pay"> 
     </div> 

    </div> 
</form> 

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script> 

    <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"></script> 



    <script type="text/javascript"> 

    function newPopup(url, width, height){ 
popupWindow = window.open(url,'_blank','height='+height+',width='+width+',left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes'); 
return false; 

    } 

    function displaybutton(displayclass){ 

    if(displayclass == 'pay'){ 
    $('.pay').css('display','block'); 
    $('#pplaunch').attr('action', 'https://www.paypal.com/cgi-binwebscr'); 
    $('#buybutton').html('Pagar'); 

    }else{ 
    $('.pay').css('display','none'); 
    $('#pplaunch').attr('action', 'http://www.example.com/archive/'+$('#issueid').val()); 
    $('#buybutton').html('Descargar'); 
      $('#descargaGratisMensaje').html('Un Me Gusta podría ser un buen intercambio'); 
} 

    } 

    function isNumber(n){ 
return !isNaN(parseFloat(n)) && isFinite(n) && (n.search(/0x/i)<0); 


     } 

    function price(n){ 

    // return null if n is not a price, or n rounded to 2 dec. places 
if(!isNumber(n)){ 
    // maybe the user entered a comma as a decimal separator 
    n = n.replace(/,/g,'.'); 
    if(!isNumber(n)){ 
     return null; 
    } 

    } 
// now we know it is a number, round it up to 2 dec. places 

    return Math.round(parseFloat(n)*100)/100; 

    } 

    function pricecheck(){ 

    var data = $.trim($('#amount').val()); 

    var myprice = price(data); 

    if(myprice == null){ 
    if(data == ''){ 
     $('#pricerror').html(''); 
    }else{ 
     $('#pricerror').html('Please enter a price.'); 
    } 
    displaybutton('pay'); 
    return false; 

    } 

    if(myprice == 0){ 
    $('#pricerror').html(''); 
    displaybutton('nopay'); 

    }else if(myprice < 0.5){ 
    $('#pricerror').html('The minimum price is '+currencysymbol+'0.50. 
    Please enter either zero, or at least '+currencysymbol+'0.50.'); 
    displaybutton('pay'); 

    }else{ 
    $('#pricerror').html(''); 
    displaybutton('pay'); 

    } 

    jQuery('.content').hide(); 

    } 

    var currencysymbol = '$'; 

    $.getScript('//www.geoplugin.ne/javascript.gp?ref=panelsyndicate.com', function() { 

    if(geoplugin_continentCode() != 'EU'){return;} 

    $('#currency').val('EUR'); 

    currencysymbol = '€'; 

    $('.currencysymbol').html(currencysymbol); 

    }); 

    $(document).ready(function(){ 

    var dialog = $('#modal').dialog({ 
    title: 'IBIZA!' 
    , autoOpen: false 
    , closeText: '' 
    , modal: true 
    , resizable: false 
    , width: 500 

    }); 

    $('#buybutton').click(function() { 
    $('#pplaunch').submit(); 

    }); 

    $('#pplaunch').submit(function() { 
    var myprice = price($.trim($('#amount').val())); 
    if((myprice != 0) && ((myprice == null) || (myprice < 0.5))){ 
     $('#pricerror').html('Please enter your price.'); 
     $('#amount').focus(); 
     return false; 
    } 

    }); 

    $('.modaltrigger').click(function() { 
    var issueid = $(this).attr('href').substr(1); 
    $('#issueid').val(issueid); // Comic ID 

    $('#include_a_message_to').html(issues[issueid].include_a_message_to); // Destinee of the message 
    dialog.dialog('option', 'title', issues[issueid].title); // Title of the comic 
    $('#issuelangs').html(issues[issueid].langs); // Languages in which the comic is available 
    dialog.dialog('option', 'position', { my: "center", at: "center", of: window }); 
    dialog.dialog('open'); 
    // prevent the default action, e.g., following a link 
    pricecheck(); 
    return false; 

    }); 

    $('#amount').bind('input propertychange', function() { 
    pricecheck(); 

    }); 

    $('.custommsg').hide(); 

    $('.msgtrigger').click(function() { 
    var cmsg = $('.custommsg'); 
    if(cmsg.is(':visible')){ 
     cmsg.hide(); 
     $('.sendmsg').show(); 
    }else{ 
     $('.sendmsg').hide(); 
     cmsg.show(); 
     $('.msgtxt').focus(); 
    } 
    return false; 

    }); 

    $('.msgtxt').keyup(function(){ 
    if($(this).val().length > maxlength){ 
     $(this).val($(this).val().substr(0, maxlength)); 
    } 
    var remaining = maxlength - $(this).val().length; 
    $('#msgtxtnumcharsleft').text(remaining); 

    }); 

    var maxlength = 200; 

    var remaining = maxlength - $('.msgtxt').val().length; 

    $('#msgtxtnumcharsleft').text(remaining); 

    }); 

    </script> 
相關問題