I have a variable(string) called "cost". If I attempt to assign it to a

我有一个名为“cost”的变量(字符串)。如果我尝试将其分配给

<p class="cost"> </p> 

it works fine. However when I attempt to assigned it to Blade generated "readonly" input I get nothing. I get no output of the "cost" value in the input field. I have tried unescaping the BLade input, also tried raw JS.

它工作正常。但是,当我尝试将其分配给Blade生成的“readonly”输入时,我什么也得不到。我在输入字段中没有输出“cost”值。我试过unescaping BLade输入,也试过原始的JS。

  $(".quantity").on('change', function(){
    var quantity = parseInt($(this).val());
    var num = (price * quantity);
    var cost = num.toString();
    $('.cost').html(cost);  // This will not assign the value ! 
});

Blade Input:

<div class="col-sm-2 col-md-2">{!! Form::text('cost[0]', null ,['class'=>'form-control cost', 'readonly'=>'readonly' ]) !!}</div>

The source code Blade produces looks like this:

Blade生成的源代码如下所示:

<div class="col-sm-2 col-md-2"><input class="form-control cost" readonly="readonly" name="cost[0]" type="text" value=""></div>

1 个解决方案

#1


2

You aren't using class="cost" on input you are using id="input" so selector needs to be changed.

您在使用id =“input”的输入上没有使用class =“cost”,因此需要更改选择器。

In addition you set value not html on inputs

另外,您在输入上设置值而不是html

Try

$('#cost').val(cost);

更多相关文章

  1. 通过],[和创建json对象来分割字符串
  2. jQuery返回一个没有逗号的字符串的前5个单词
  3. 将Object转换为字符串并返回[复制]
  4. 带有括号的某些字符串导致Ajax POST操作失败,出现403错误(禁止)
  5. 使用jQuery在AJAX调用中的url字段格式
  6. 可编辑的表格:jQuery+PHP实现实时编辑表格字段内容
  7. 为什么我不能在同一个js文件中建立两个cleave.js格式的字段?
  8. 在使用javascript将信息输入到输入字段时填充文本区域
  9. 为什么在使用jquery读写表单输入时必须对字符串进行编码?

随机推荐

  1. android 测试简介
  2. Android应用程序安装过程源代码分析(4)
  3. Android 学习笔记--android――Notificat
  4. 解决 ButterKnife8.2.1 与 Dagger2.5 冲
  5. webview 底部被遮住
  6. Cocos2d-x权限问题
  7. Android 手机震动
  8. android SDK manager 无法获取更新版本列
  9. Android Studio3.1.2 build.gradle class
  10. Android简单明了的使用属性动画ObjectAni