English 中文(简体)
通过支架从档案库中获取价值
原标题:To get the value from file upload field by jquery
  • 时间:2012-05-11 06:09:48
  •  标签:
  • jquery

i have contact form and there i used a file upload file. now i want to get the value it means the path from the file upload field by jQuery. The file upload field has the class named filebrowse and i want to store the value and echo the value in another input field. i used this code for retrieve the path

var val = jQuery(".filebrowse").val();
console.log(val);
jQuery( .file-input ).attr( value , val);

it works but it didnot show the value in the input box field. becoz by default the input box is empty so it shown nothing. now i want to display the value in the input box when one browse file to the file upload field.

问题回答

您指的是,为了获得档案领域的价值:

$( .filebrowse ).change( function(){
    console.log( $(this).val() );
});

由于安全原因,不可能确定档案投入的价值。 这样做将使恶性 j有可能使你确定档案,然后按方案提交表格,使他们能够通过强迫上载在你的系统中偷窃任何档案,只要他们知道这样做的道路。

Edit - heh, I misread the question and answered based on the example code. It s generally possible to get the filename of the value of a file input, but it will not include the path, again for security reasons.

根据您的问答和陈述,有两部分标明价值(工作)并显示其他非工作投入的价值。

选择输入类型对文件的价值是正确的,但顺序很重要。 确保管理局的顺序正确控制职能,然后在支部中使用。

页: 1

确保贵格会的挑选者在文件内准备好,并参加变化活动。

备选办法1:通过变更活动控制职能。

function fileUploadChanged(fileUploader) {
  let path = $(fileUploader).val();
  console.log( Path:= , path);
  $( #fileSelectedOutput ).val(path);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<!-- FILE UPLOAD -->
<input type="file" style="width:100%;" class="fu" id="fileUploader" name="fileUploader" onchange="fileUploadChanged(this)" />

<!-- OUTPUT -->
<input id="fileSelectedOutput" type="text" />

备选案文2:确保变更活动受已准备好的文件内控制。

$(document).ready(function() {
  $( #fileUploader ).change(function() {
    let path = $(this).val();
    console.log( Path:= , path);
    $( #fileSelectedOutput ).val(path);
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<!-- FILE UPLOAD -->
<input type="file" style="width:100%;" class="fu" id="fileUploader" name="fileUploader" />

<!-- OUTPUT -->
<input id="fileSelectedOutput" type="text" />




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签