我有这个TextField内的事业部
<div id="mainDiv">
<input type="text" value="Here is the text" />
</div>
<input type="button" value="Push" onclick="changeText()">
当我推我想改变文本框从价值的按钮。
只有这个值我想更改,因为在我的页面中有很多文本区域,但这些值必须保持不变。
我有这个TextField内的事业部
<div id="mainDiv">
<input type="text" value="Here is the text" />
</div>
<input type="button" value="Push" onclick="changeText()">
当我推我想改变文本框从价值的按钮。
只有这个值我想更改,因为在我的页面中有很多文本区域,但这些值必须保持不变。
试试这个
<div id="mainDiv">
<input type="text" value="Here is the text" />
</div>
<input type="button" value="Push" onclick="document.getElementById('mainDiv').children[0].value='asd'">
那么,也许这将帮助:
<script>
function changeText() {
var tf = document.getElementById('mainDiv').childNodes[0];
tf.value = 'some text';
}
</script>
<div id="mainDiv"><input type="text" value="Here is the text" /></div>
<input type="button" value="Push" onclick="changeText();">
对不起,我忘了添加这条评论div的结构我不能改变。它是从DataTables Jquery生成的。添加一个ID很容易,但不幸的是,我不能这样做 – tinti 2011-05-27 13:46:21
我编辑了我的答案......这有帮助吗? – 2011-05-27 13:51:14
尝试与子的id文本框的ID绑定代码 这样的:
<div id="mainDiv"> <input type="text" value="Here is the text" id="input-324" /> </div> <input type="button" value="Push" onclick="changeText(this.id.replace("button-", ""))" id="button-324" >
<script>
function changeText(id) {
document.getElementById(id).value='myvalue';
}
</script>
您是否正在寻找对于这样的事情?基本上切换输入为静态文本?
function changeText(){
var mainDiv = $("#mainDiv");
mainDiv.text(mainDiv.children('input').val());
}
如果每个DIV多个输入字段该解决方案将工作,
function changeText(){
var mainDiv = $("#mainDiv"),
inputText = "";
if(mainDiv.children('input').length > 0){
mainDiv.children('input').each(function(){
inputText += $(this).val();
});
mainDiv.text(inputText);
}
}
耶我的第一个答案:) – 2011-05-27 14:03:47