2011-04-02 74 views

回答

1
jQuery solution - check it out (jQuery that is) 
$('#button').click(function(e) { 
    e.preventDefault(); 
    $('#totextarea').val($('#fromtextarea').val()); 
    ...then submit the form if you wish to or whatever... 
    $('#theform').submit(); 
}); 
+1

@ kjy112:感謝隊友:-D – Splynx 2011-04-02 18:59:12

+0

歡迎您=)! – kjy112 2011-04-02 18:59:47

1

假設你有這樣的:

<textarea id="source"></textarea> 
... 
<textarea id="target"></textarea> 
... 
<button type="button" onclick="update();">Update</button> 

那麼你的JS功能可以是:

function update() { 
    document.getElementById('target').value = document.getElementById('source').value; 
} 
+0

它仍然不更新-_- – TotallyPwnage 2011-04-02 19:27:50

+0

包括你的html和JS請 – moe 2011-04-02 22:41:38

0
<script> 
function sync() 
{ 
    // Take first and second value by element ID 
    var n1 = document.getElementById('n1'); 
    var n2 = document.getElementById('n2'); 
    // Assign the value of the 1st to the 2nd text box 
    n2.value = n1.value; 
} 
</script> 

<input type="text" name="n1" id="n1" /> 
<input type="text" name="n2" id="n2"/> 
<!-- you put a function sync to be executed on click on the button --> 
<button onclick="sync()">Synchronize</button> 
0

請嘗試以下

<script> 
function onSubmitClick() { 
    var box1 = document.getElementById('box1'); 
    var box2 = document.getElementById('box2'); 
    box2.value = box1.value; 
} 
</script> 

<textarea id='box1'></textarea> 
<textarea id='box2'></textarea> 
<button onclick='onSubmitClick(); return false'>Click Me</button> 

的jsfiddle演示

相關問題