JS如何替换文本框VALUE的值?

JavaScript010

JS如何替换文本框VALUE的值?,第1张

有办法,并且很简单。

1、把触发事件改掉。原来是按钮的onclick事件,改成文本框的onchange事件。

2、把onchange事件的处理函数修改一下。

大概就是下面这种样子

<input id="q" name="kw" type="text" placeholder="请输入要查询的内容" onchange="this.value=zh_tran('t',this.value)">

function center() {

if (document.selection &&document.selection.type == 'Text') {

var word = document.selection.createRange()

word.text = '[align=center]' + word.text + '[/align]'

}

}