簡體   English   中英

使用 jquery 更改元素文本值不起作用

[英]Change element text value using jquery not work

我有一種從 rails 生成的表單。 我試圖在 firefox firebug 控制台中使用 Jquery 更改為輸入order_bill ,但它不起作用。 我是jQuery新手。

<form class="edit_order" id="edit_order_1" action="/orders/1" accept-charset="UTF-8" method="post">
    <input name="utf8" type="hidden" value="&#x2713;" /><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>

在螢火蟲 JS 控制台中,

$('#order_bill').html("asdasdddddddddddddddd");
$('#order_bill').html("asdasdddddddddddddddd");
$('#order_bill').html("asdasdddddxx");
$('#bill').html("asdasdddddxx");

但是 Html 頁面上沒有任何變化。 我錯了嗎?

嘗試這個:

$('#order_bill').val("asdasdddddddddddddddd");

而不是html();

因為要更改的值存在於標簽的 value 屬性中。

您可能需要確保在 html 頁面中導入 jquery 庫http://code.jquery.com/jquery-2.2.4.min.js

如果你想獲得價值,只需輸入 $('#order_bill').value

並設置值 $('#order_bill').value = "enter Value"

但是如果您想使用 jquery 在 div 中添加文本

$('#order_bill').html("Value");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM