【问题标题】:Jquery update ckfinder form fieldjQuery 更新 ckfinder 表单字段
【发布时间】:2016-11-07 19:38:00
【问题描述】:

我正在尝试通过 ck finders 弹出图像选择器更新输入字段值.ckfinder-input。 一切正常,直到我尝试将所选图像 URL 分配给输入字段 input.val() = fileUrl 并收到以下错误消息:

ReferenceError: 左侧赋值无效

有人能解释一下我做错了什么吗?

我的代码如下:

$(".ckfinder-modal-button").on("click", function() {
  input = $(this).parent().find(".ckfinder-input");
  BrowseServer(input);
});

function BrowseServer(input) {
  var finder = new CKFinder();
  finder.selectActionData = input;
  finder.selectActionFunction = function(fileUrl, data) {
    input = data['selectActionData'];
    console.log(input); //returns Object[input.form-control.ckfinder-input property value = "" attribute value = "null"]
    console.log(fileUrl); //returns "/customer_images/header_images/home.jpg"
    input.val() = fileUrl; // ReferenceError: invalid assignment left-hand side;
  }
  finder.resourceType = 'HeaderImages';
  finder.removePlugins = 'basket';
  finder.popup();
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="bootstrap-filestyle input-group">
  <input type="text" class="form-control ckfinder-input" name="ckfinder-input">
  <span class="group-span-filestyle input-group-btn ckfinder-modal-button" tabindex="0">
    <label class="btn btn-default">
      <span class="icon-span-filestyle fa fa-cloud-upload"></span>
  </label>
  </span>
</div>

【问题讨论】:

    标签: javascript jquery ckfinder


    【解决方案1】:

    可能是因为您的 JavaScript 无效。您不能将值 (fileUrl) 分配给函数 (input.val()) 的输出: js input.val() = 'abc'; 您应该:

    a) 如果是DOM Input Element input.value = 'abc';

    b) 如果是jQuery wrapper for DOM Element input.val( 'abc' );

    【讨论】:

    • 啊-谢谢-我改成input.val(fileUrl),效果很好。
    猜你喜欢
    • 2016-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多