如何将JQuery变量值分配给Laravel Blade输入
16lz
2021-01-22
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);
更多相关文章
- 通过],[和创建json对象来分割字符串
- jQuery返回一个没有逗号的字符串的前5个单词
- 将Object转换为字符串并返回[复制]
- 带有括号的某些字符串导致Ajax POST操作失败,出现403错误(禁止)
- 使用jQuery在AJAX调用中的url字段格式
- 可编辑的表格:jQuery+PHP实现实时编辑表格字段内容
- 为什么我不能在同一个js文件中建立两个cleave.js格式的字段?
- 在使用javascript将信息输入到输入字段时填充文本区域
- 为什么在使用jquery读写表单输入时必须对字符串进行编码?