如何在没有按钮点击的情况下将值输入文本框

时间:2013-09-04 09:28:50

标签: javascript html

使用如下

 <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>

这里的问题是,当点击文本框时它只是获取或更改值我需要值而不点击文本框我必须做什么。有人帮帮我

3 个答案:

答案 0 :(得分:0)

尝试做:

document.getElementById('actual_total_marketing_budget').value

在行动中查看here。 但是,回答了类似的问题here

答案 1 :(得分:0)

您已在onFocus事件中编写了获取textbox值的函数。

将其更改为文档加载,如

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

JSFiddle

中查看此内容

答案 2 :(得分:0)

你可以这样做;

<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()之后调用了函数,该函数在页面加载后会更改文本框的值。

相关问题