2013-01-07 28 views
0

單擊按鈕後,javascript在新選項卡上顯示結果。但是我想要將結果顯示在按鈕下方。在頁面上不顯示結果的Html單擊事件(使用javascript)

<html> 
<body> 
    <input type="button" id="button1" value="Click Here" onclick="print();"/> 

    <script type="text/javascript"> //script to do some task 
    function print() 
    {   

    document.write('My Text Goes here '); 

    } 
    </script> 
</body> 

+0

使用document.write不是一個好習慣。 –

+1

旁邊它工作正常檢查這個小提琴:[http://jsfiddle.net/wk7cS/](http://jsfiddle.net/wk7cS/) –

+0

http://stackoverflow.com/questions/9017754/open-in-新標籤與動態內容和http://stackoverflow.com/questions/427479/programmatically-open-new-pages-on-tabs可能對你有用 – KarSho

回答

0

只能完全加載頁面之前文件撰寫使用。

如果你想在頁面加載後添加文本,你必須改變DOM使用一些本地JavaScript函數(appendChild,createElement等),或者你可以使用jQuery(或其他JavaScript框架)。第二個更容易,因爲你不需要關心瀏覽器兼容性。

jQuery的如:

$( 「#Button1的」)後( 「我在此輸入文字」);

相關問題