1
我有一個頁面,頁面有兩個圖片選擇器。我編碼其中一個用於顯示圖片,當我選擇一個圖片文件。但我想單獨使用它們。我嘗試了它作爲附加的代碼。你能幫我一下,我怎麼能分開他們呢?另外我怎樣才能用PHP,Javascript或jQuery分別創建清晰的按鈕?圖像選擇器不止一個
我試着作爲我的代碼,它只適用於一個選擇器,而不是其他。
<form id="form1">
<input type="file" id="image-1-selector">
<img src="#" id="first-image">
<button type="reset" onclick="clearFile(event)">Clear</button><br /><br />
<input type="file" id="image-2-selector">
<img src="#" id="second-image">
<button type="reset" onclick="clearFile(event)">Clear </button>
</form>
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
$('#first-image').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#image-1-selector").change(function() {
readURL(this);
});
var clearFile = function(event) {
var output = document.getElementById('first-image');
output.src = '';
};
這是我的示例代碼,它不會像我問 [我的示例程序(https://jsfiddle.net/underspeed/hsurwuod工作/#&togetherjs = dfuSRevdHA) –
var clearFile = function(event){'不會在jsfiddle上工作。 – RRK
是的,但你知道它是什麼,對吧? –