0

我在使用 javascript 编码方面很新,我有这个问题:我有 uploadify 配置,我有这一行:

  // <![CDATA[
  $(document).ready(function() {
      $('#file_upload').uploadify({
          'uploader'  : 'js/uploadify/uploadify.swf',
          'script'    : 'ajaxup.php<?php if(isset($_SESSION['user_id'])) { echo "?session_id=" . session_id() ; } ?>',
          'cancelImg' : 'css/img/cancel.png',
          'auto'      : true,
          'displayData' : 'speed',
          'multi'       : true,
          'fileDataName' : 'uploaded',
          'fileExt'     : '*.jpg;*.gif;*.png;*.jpeg',
          'fileDesc'    : 'Image Files',
          'queueSizeLimit' : 30,
          'simUploadLimit' : 1,
          'sizeLimit'   : 5024*1024,
          'scriptData'         : {'postkey' : postValueVariable},

          'onOpen'      : function() {

              document.getElementById('index_upload').style.cssText = 'width: 600px !important';
              document.getElementById('ajax_allbbcodes').style.cssText = 'display:inherit;';

              $("#ajax_bbcodes").animate({
                  width: "500",
                  height: "100"
              }, 1000 );

              $("#ajax_HTMLcodes").animate({
                  width: "500",
                  height: "100"
              }, 1000 );

              $("#ajax_DirectLinks").animate({
                  width: "500",
                  height: "100"
              }, 1000 );
              <?php if(DIRECT_LINK_SHOW == 1) { ?>
              $("#ajax_DirectLinkToImgs").animate({
                  width: "500",
                  height: "100"
              }, 1000 );
              <?php } ?>
          },
          'onProgress'  : function(event,ID,fileObj,data) {
              var bytes = Math.round(data.bytesLoaded / 1024);
              $('#' + $(event.target).attr('id') + ID).find('.percentage').text(' - ' + bytes + 'KB Uploaded');


              document.getElementById('progressbarOver').style.cssText = 'display:inherit;';


              $("#progressbar").animate({
                  width: data.percentage + "%",
                  height: "20"
              }, 200 );


              return false;
          },
          'onComplete'  : function(event, ID, fileObj, response, data) {

              old_guests = document.getElementById("testajax").innerHTML;
              document.getElementById('testajax').innerHTML = old_guests + response;

              myArrayBBCode = $('.ajax_BBCode');
              oldbb = document.getElementById('ajax_bbcodes').innerHTML;
              document.getElementById('ajax_bbcodes').innerHTML = oldbb + myArrayBBCode[myArrayBBCode.length-1].innerHTML + ' ';

              myArrayHTMLCode = $('.ajax_HTMLCode');
              oldbbHTMLCode = document.getElementById('ajax_HTMLcodes').innerHTML;
              document.getElementById('ajax_HTMLcodes').innerHTML = oldbbHTMLCode + myArrayHTMLCode[myArrayHTMLCode.length-1].innerHTML + ' ';

              myArrayDirectLink = $('.ajax_DirectLink');
              oldbbDirectLink = document.getElementById('ajax_DirectLinks').innerHTML;
              document.getElementById('ajax_DirectLinks').innerHTML = oldbbDirectLink + myArrayDirectLink[myArrayDirectLink.length-1].innerHTML + ' \r\n';

            <?php if(DIRECT_LINK_SHOW == 1) { ?>
              myArrayDirectLinkToImg = $('.ajax_DirectLinkToImg');
              oldbbDirectLinkToImg = document.getElementById('ajax_DirectLinkToImgs').innerHTML;
              document.getElementById('ajax_DirectLinkToImgs').innerHTML = oldbbDirectLinkToImg + myArrayDirectLinkToImg[myArrayDirectLinkToImg.length-1].innerHTML + ' \r\n';
            <?php } ?>




          },
          'onAllComplete' : function(event,data) {
              document.getElementById('progressbarOver').style.cssText = 'display:none;';
          }


      });
  });

  // ]]>

我需要有两个具有 onclick 功能或其他功能的按钮,当按下时,将postValueVariable更改为 Yes 或 No 。我尝试了很多方法,但没有奏效。希望我能在这里找到答案。先感谢您 !

4

1 回答 1

0

应该可以帮助您入门。

<button data-boolean='yes'>button one</button>
<button data-boolean='no'>button two</button>

window.postValueVariable = null;

updateValueVariable = function () {
    window.postValueVariable = this.getAttribute('data-boolean');
    alert('postValueVariable is now ' + window.postValueVariable);
};

var buttons = document.querySelectorAll('button');

for (var i = 0; i < buttons.length; i += 1) {
    var button = buttons[i];
    (function () {
        button.addEventListener('click', updateValueVariable, false);
    }())
}
于 2012-10-02T06:42:11.417 回答