我在使用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 更改为是或否。我试过很多方面,但没有奏效。希望我能在这里找到答案。提前谢谢!
答案 0 :(得分:0)
This 应帮助您入门。
<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);
}())
}