你需要做的是從getContent()
呼叫作爲解析返回的字符串HTML!正如你用jQuery標記了你的文章,我假設爲此需要使用jQuery。隨着中說,你解決你的TincyMCE選擇內檢索a
元素的href
值,請執行下列操作:
// This value of var selectionFromTinyMCE is an example
// of what parent.tinyMCE.activeEditor.selection.getContent(); returns to you
var selectionFromTinyMCE = 'sit our <a href="../forum/index.php">community forum</a>! We also';
// Here we take the string returned by TinyMCE, wrap it with a span tag,
// and pass it into a jQuery. This forces jQuery to evaluate the string as HTML!
var $jStr = $("<span>"+selectionFromTinyMCE+"</span>");
// You then create new variable and store the value of the href attribute
// of the <a> element from within your string.
var hrefValueFromTinyMCEselection = $jStr.find("a").attr("href");
// Check the console to see the result below, outputted as a string
console.log(hrefValueFromTinyMCEselection);
下面的代碼的的jsfiddle版本上面看到它發生現場(開控制檯查看結果記錄):http://jsfiddle.net/lasha/NF9V8/
你能顯示一個實際的字符串,它被存儲爲你的'selection'變量嗎?我想看看TinyMCE用'.getContents()'函數調用實際返回的結果。我可能有一個解決方案爲你準備... – Lasha
其實,我已經想通了。很快回答。 :) – Lasha