簡體   English   中英

如何在不單擊按鈕的情況下將價值帶入文本框

[英]how to get value into textbox without button click

正在使用如下

 <input type="text" value="<?php echo empty($this->session->store['actual_info']['actual_total_marketing_budget']) ? '' : $this->session->store['actual_info']['actual_total_marketing_budget']; ?>"  readonly name="actual_total_marketing_budget" readonly id="actual_total_marketing_budget"  size="30" style="height:20px; " onFocus="total_marketing_budget()"/></td>

在這里,單擊文本框時的問題僅是獲取或更改值,而無需單擊文本框就需要該值。 有人幫我

嘗試做:

document.getElementById('actual_total_marketing_budget').value

在這里看到它。 但是, 這里回答了類似的問題。

您已在onFocus事件中編寫了獲取文本框值的函數。

將其更改為文檔加載時的樣子

<script>    
(function() {
        var textBox = document.getElementById('actual_total_marketing_budget').value
    })();
</script>

JSFiddle中檢查一下

你可以這樣做

<input type ="text" value="...." id ="actual_total_marketing_budget">


<script type="text/javascript">
function actual_total_marketing_budget(){
var textbox = document.getElementById('actual_total_marketing_budget');

//the function body is the same as you have defined sue the textbox object to set the value
}

actual_total_marketing_budget();
</script>

在這里請注意,我在定義了函數后調用了actual_total_marketing_budget()函數,該函數在頁面加載后會更改文本框的值。

暫無
暫無

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

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