[英]Change element text value using jquery not work
I have one form generated from rails.我有一种从 rails 生成的表单。 I tried to change to the input
order_bill
using Jquery in the firefox firebug console, but it does not work.我试图在 firefox firebug 控制台中使用 Jquery 更改为输入
order_bill
,但它不起作用。 I am new to jQuery
.我是
jQuery
新手。
<form class="edit_order" id="edit_order_1" action="/orders/1" accept-charset="UTF-8" method="post">
<input name="utf8" type="hidden" value="✓" /><input type="hidden" name="_method" value="patch" />
<input type="hidden" name="authenticity_token" value="1IBaRCZ4S1hYp1" />
..
<div id="bill", class="field">
<label for="order_应付款项">应付款项</label><br>
<input type="text" value="4200" name="order[bill]" id="order_bill" />
</div>
<div class="actions"> .. </div>
<div class="actions">
</div>
</form>
In the firebug JS console,在萤火虫 JS 控制台中,
$('#order_bill').html("asdasdddddddddddddddd");
$('#order_bill').html("asdasdddddddddddddddd");
$('#order_bill').html("asdasdddddxx");
$('#bill').html("asdasdddddxx");
But none change on the Html page.但是 Html 页面上没有任何变化。 Am I wrong?
我错了吗?
Try this:尝试这个:
$('#order_bill').val("asdasdddddddddddddddd");
instead of html();
而不是
html();
because the value you want to change is present in value attribute of tag.因为要更改的值存在于标签的 value 属性中。
You may need to make sure you import a jquery library in your html page http://code.jquery.com/jquery-2.2.4.min.js您可能需要确保在 html 页面中导入 jquery 库http://code.jquery.com/jquery-2.2.4.min.js
if you want to get value just Type $('#order_bill').value如果你想获得价值,只需输入 $('#order_bill').value
and set the value $('#order_bill').value = "enter Value"并设置值 $('#order_bill').value = "enter Value"
But if You Want to add a text in div using jquery但是如果您想使用 jquery 在 div 中添加文本
$('#order_bill').html("Value"); $('#order_bill').html("Value");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.