我有這個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