跳到主要內容

發表文章

目前顯示的是 9月, 2015的文章

在contenteditable裡的固定位置插入html

<div id="test" contenteditable="true">Some editable text</div> < input type="button" unselectable="on" onclick="displayTextInserter();" value="Insert text"> <div id="textInserter"> <input type="text" id="textToInsert"> <input type="button" onclick="insertText()" value="Insert"> </div> <script type="text/javascript"> function saveSelection() { if (window.getSelection) { sel = window.getSelection(); if (sel.getRangeAt && sel.rangeCount) { return sel.getRangeAt(0); } } else if (document.selection && document.selection.createRange) { return document.selection.createRange(); } return null; } function restoreSelection(range) { if (range) { if (window.getSelection) { sel = window.getSelection(); ...

存取iframe元素

$(function () { $('#_iframe').load(function () { var $iframe = $(this), $contents = $iframe.contents(); // 取得 iframe 中的元素 var t1 = $contents.find('#t1').val(); // 取得 radio checked value var checkedVal = $contents.find("[name='uploadType']:checked").val(); // 設定 iframe 中的元素 $contents.find('#t2').val('我的值是由外部指定的!!'); $contents.find('#t2').css('color', 'red'); // 控制 iframe 中的按鈕觸發事件 $contents.find('#sbtn1').click(); // 執行 iframe 中定義的方法 $iframe.get(0).contentWindow.iframeMethod(); // 執行各種動作時可以再判斷 $contents 是否為 null }); });